Help using Base SAS procedures

Passing multiple values in call symput

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Passing multiple values in call symput

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?


Accepted Solutions
Solution
‎11-29-2017 12:08 AM
Occasional Contributor
Posts: 12

Re: Passing multiple values in call symput

This worked.thanks a lot.

View solution in original post


All Replies
Super User
Posts: 23,773

Re: Passing multiple values in call symput

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;
Super User
Posts: 13,583

Re: Passing multiple values in call symput

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.

 

Solution
‎11-29-2017 12:08 AM
Occasional Contributor
Posts: 12

Re: Passing multiple values in call symput

This worked.thanks a lot.
Super User
Posts: 23,773

Re: Passing multiple values in call symput

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1048 views
  • 1 like
  • 3 in conversation