SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sharathr
Obsidian | Level 7
Hi forum,
Is it possible to pass multiple values to a macro variable created in call symput.
Data sample;
Infile data lines;
Input name $;
Data lines;
John
Mark
Carl
;
Data _null_;
Set sample;
Call symput(name1,name);
Run;

How can I assign the each data step values separately to macro variable and use it in my code?

1 ACCEPTED SOLUTION

Accepted Solutions
Sharathr
Obsidian | Level 7
This worked.thanks a lot.

View solution in original post

4 REPLIES 4
Reeza
Super User

Are you trying to create a single macro variable or many here? Personally, I find SQL easier to use in these cases. 

 

Multiple macro variables:

 

Proc sql noprint;
Select name into : name1-
From sashelp.class;
Quit;%put &name1.;%put &name19.;

Single macro variable, delimited by space:

 

Proc sql noprint;
Select name into :name_list separated by “ “
From sashelp.class; 
Quit;%put &name_list;
ballardw
Super User

The following datastep creates a single macro variable for each record in your set and a variable that has the count.

Data _null_;
   Set sample;
   mvarname= catt('name',_n_);
   Call symputx(mvarname,name);
   call symputx('numnames',_n_);
Run;

Old school, as in SAS 6. I would go with @Reeza's Proc SQL most of the time these days.

 

Sharathr
Obsidian | Level 7
This worked.thanks a lot.
Reeza
Super User

@Sharathr please choose someone else's answer as the solution, not your own.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 10819 views
  • 2 likes
  • 3 in conversation