Solved

Resolving to Macro variables in SAS

Posted on 2011-09-23
1
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

688 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