This widget could not be displayed.
This widget could not be displayed.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Hi, all:

 

I have a macro statement created by a previous coworker.   Could anyone explain what the "call symputx" part and the "if" condition after "call symputx" are for?  Thanks.

 

Y

 

%macro list(lib,sect);

     

      data &sect.c;

            set &sect.a(rename=(name=name_sup));

 

            stabb=scan(name_sup,1,"_");

      run;

 

      data _null_;

            set &sect.c end=eof;

            by name_sup;

 

            j+1;

 

            call symputx("name"||trim(left(put(j,8.))),name_sup,'G');

            call symputx("stabb"||trim(left(put(j,8.))),stabb,'G');

            if eof then call symputx("count_state",j,'G');

      run;

 

%mend list;

 

1 ACCEPTED SOLUTION

Accepted Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
if eof

 

tests when you have reached the very last observation of the SAS data set you are processing

 

call symputx

 

 

creates a global macro variable named "count_state" from the value of the data set variable j in that last observation

--
Paige Miller

View solution in original post

7 REPLIES 7
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
if eof

 

tests when you have reached the very last observation of the SAS data set you are processing

 

call symputx

 

 

creates a global macro variable named "count_state" from the value of the data set variable j in that last observation

--
Paige Miller
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

What is the following for?

 

call symputx("name"||trim(left(put(j,8.))),name_sup,'G');

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

@ybz12003 wrote:

What is the following for?

 

call symputx("name"||trim(left(put(j,8.))),name_sup,'G');


creating a series macro variables

Name1 , Name2, Name3 etc holding the values for variable Name_sup for each record in the input data set.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

What is the 'G' for?

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Thanks,  I just read through it.

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
You need to use the 'G' option to have the macro variables created as GLOBAL instead of LOCAL. Otherwise if the macro variables are not already defined then they will be created as LOCAL to the utility macro and thus disappear when the macro finishes running. Making them GLOBAL is one way to make sure the values are available later in your program after the macro has finished.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 2271 views
  • 4 likes
  • 4 in conversation
This widget could not be displayed.
This widget could not be displayed.