BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
deleted_user
Not applicable
Thank you, I got it
deleted_user
Not applicable
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 895 views
  • 0 likes
  • 2 in conversation