Solved

Resolving to Macro variables in SAS

Posted on 2011-09-23
1
510 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

757 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

16 Experts available now in Live!

Get 1:1 Help Now