Solved

Resolving to Macro variables in SAS

Posted on 2011-09-23
1
515 Views
Last Modified: 2013-11-16
Hi all,

I have a SAS dataset with one column as

EP
1
2
3
4

and i need to resolve the rows of this sas datasets  as below

%let par1 = %str(1,2,3,4);

the number of rows in the dataset are dynamic and they change everytime.

Can any one please help me on this.

Thanks in advance!!



0
Comment
Question by:aruku
1 Comment
 
LVL 7

Accepted Solution

by:
d507201 earned 500 total points
ID: 36590216
Here I use a RETAIN statement to build the value of a string variable and after the last record is processed I use CALL SYMPUT to create the macro variable.  You will have to adjust the length of the String variable based on the maximum expected number of EP values and how many digits are in each value.

I find it curious that 'Numeric to Character conversion' warning isn't printed in the log when string is created, but maybe the CATX function supresses it.


data one;
	infile cards;
	input ep 8.;
cards;
1
2
3
4
;
run;

data two; 
	** Set the attributes of a variable named string.  Make it longer just in case. ;
	attrib string length=$20 format=$20.;
	** Retain the value of string across iterations of the data step. ;
	retain string;

	** read the source dataset and set a flag that will =1 when the last record is processed. ;
	set one end=eof;

	** At the first obs initialize string as blank;
	if _n_=1 then string='';

	** For each obs, add the value of ep to the string separated by a comma.;
	** CATX inserts the separator and trims leading and trailing blanks.    ;
	string=catx(',',string,ep); **input(put(ep,8.),$2.);

	put ep string;

	** When the last record is processed, create the macro variable. ;
	if eof then call symput('par1',string);
run;

%put par1= &par1;

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now