LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 23 May 2009 18:14:21 -0400
Reply-To:     Ian Whitlock <iw1sas@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1sas@GMAIL.COM>
Subject:      Re: Convert numeric to character,
              but don't know the length of the numeric variable.
Content-Type: text/plain; charset=ISO-8859-1

From: Huijuan Meng <huijuan_meng@HOTMAIL.COM> Subject: Re: Convert numeric to character, but don't know the length of the numeric variable.

Summary: Test data and two solutions iw-value=1

data mydata ; do x = 1 to 999 ; output ; end ; run ;

proc sql noprint ; select put (nobs,best12.) into :c1n from dictionary.tables where libname = "WORK" and memname = "MYDATA" ; quit ;

data _null_ ; file log; l1 = cats ( ">INAmes = (Q1(1)Q", "&c1n", ");" ) ; l2 = cats ( ">INUmber = (1(1)", "&c1n", ");" ) ; put l1 / l2 ; RUN;

%let c1n = &c1n ; /* strip lead and trailing spaces */

data _null_ ; file log; put @1 ">INAmes = (Q1(1)Q" "&c1n." ");"/ @1 ">INUmber = (1(1)" "&c1n." ");"/ ; run ;

Ian Whitlock

Date: Sat, 23 May 2009 05:17:12 +0800 From: Huijuan Meng <huijuan_meng@HOTMAIL.COM> Subject: Re: Convert numeric to character, but don't know the length of the numeric variable.

Thank you so much for your help, sorry I did not explain my question more specific.

Here is my situation:

I have a dataset which contain, say, 1100 variables,

I run some analysis with this data, based on the results, I need to delete certain variables,

Then I need to find the number of the rest of the variables, it can be >=1000, or < 1000,

Finally, I need to write a text file which referring to this number a couple of times, and I don't want any space between this number and other words in the text file.

Now I have a global macro variable:

%global c1n;

In my macro, I have

data t1;

dsid = open ("mydata");

c1n0 = attrn (dsid,'nobs');

c1n=put(c1n0,4.0);

run;

proc sql noprint; select c1n into :c1n from t1; quit;

data textfile;

file "C:\textfile.txt";

@1 ">INAmes = (Q1(1)Q" "&c1n." ");"/

@1 ">INUmber = (1(1)" "&c1n." ");"/

;

RUN;

So if c1n=999, I want my text file looks like:

>INAmes = (Q1(1)Q999);

>INUmber = (1(1)999);

Instead of

>INAmes = (Q1(1)Q 999);

>INUmber = (1(1) 999 );

I hope that makes sense.

Thanks a lot.


Back to: Top of message | Previous page | Main SAS-L page