?
Solved

Resolving to Macro variables in SAS

Posted on 2011-09-23
1
Medium Priority
?
556 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 2000 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

Industry Leaders: 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 …
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

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