Help using Base SAS procedures

create macro variables for list of observations

Reply
N/A
Posts: 0

create macro variables for list of observations

hi,

I have a data set with one column which looks like this

VAR1
a
b
c
d
e
.
k


I need to create macro variables for each observation, like:

&name1 = a
&name2 = b
..

Can you tell me how can i do that?
Super Contributor
Super Contributor
Posts: 3,174

Re: create macro variables for list of observations

Posted in reply to deleted_user
Using PROC SQL, you can use the SELECT INTO :V1-Vnn technique to generate the SAS macro variables.

Here is a useful Google advanced search argument which provides some matches for reference and examples:

proc sql generate macro variable list into site:sas.com

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: create macro variables for list of observations

I tried to do the same thing but it wasnt doing it.

proc sql;
select column1 into :name1-:name&totobs
from work.filenames_list;
quit;

%put &&name&5;
(It does not resolove)

I think I'm writing it wrong at name&totobs. How should I do it?
Super Contributor
Super Contributor
Posts: 3,174

Re: create macro variables for list of observations

Posted in reply to deleted_user
After your PROC SQL executes, issue the command:

%PUT _USER_;

The output will show you the SAS macro variables generated, if any, by your PROC SQL execution.

And if you are trying to iterate through the variable list, please share all of the related macro code you are executing, preferably in a SAS log perspective, with any errors. This info will help with providing feedback.


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: create macro variables for list of observations

When I use %put _user_;
It does list all the variables in the log. But, It does not resolve when i use %put &&name&i.

My later part of the code looks like this and it does not resolve there too.


853
854
855 %do i=1 %to &totobs;
ERROR: The %DO statement is not valid in open code.
856
857 %if %sysfunc(fileexist("C:\DandS\Mydoc\RawData\&&name&i..dat")) = 1
ERROR: The %IF statement is not valid in open code.
858 %then %do;
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
Super Contributor
Super Contributor
Posts: 3,174

Re: create macro variables for list of observations

Posted in reply to deleted_user
You have SAS macro code %DO/%END that is not contained in a defined macro, which is required.

Scott Barry
SBBWorks, Inc.

SASâ Macro Programming for Beginners
Susan J. Slaughter, Avocet Solutions, Davis, CA
Lora D. Delwiche, Delwiche Consulting, Winters, CA
http://www2.sas.com/proceedings/sugi29/243-29.pdf

Using PROC SQL with the SAS Macro Facility
http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a001360983.htm
N/A
Posts: 0

Re: create macro variables for list of observations

Thank you, I got it
N/A
Posts: 0

Re: create macro variables for list of observations

Posted in reply to deleted_user
This work can be also done with the SYMPUT CALL in a data step:

data have;
input var1 $ @@;
cards;
a b c d e f g
;

data _null_;
set have;
call symput ("name"||strip(_n_),var1);
run;

%put _global_;


Yuewei
Ask a Question
Discussion stats
  • 7 replies
  • 110 views
  • 0 likes
  • 2 in conversation