Solved

Resolving to Macro variables in SAS

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display multiple images in report 12 118
MySQL ERROR 1045 (28000) 2 78
Exchange 2010 Database wont mount 3 45
SQL Query assistance 16 24
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

770 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