BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kuridisanjeev
Quartz | Level 8

Hi every one...

Is it possible to create a macro variable by Using ODS statement???

If YES ,could you please explain..,,,

Thanks

Sanjeev.k

1 ACCEPTED SOLUTION

Accepted Solutions
Hima
Obsidian | Level 7


The MATCHALL= option for the OUTPUT destination on the ODS statement can be used to name a macro variable that will
contain a list of SAS data tables. In the following example a PROC UNIVARIATE is executed with a BY statement. For each
value of the BY variable (PRODUCT) a data set will be created which will contain the summary known as MOMENTS. The
MATCHALL option requests separate data sets and the list of the names of these data sets is to be written to the macro
variable &NAMELIST.
ods output Moments(match_all=namelist)=work.Moments;
proc univariate data=magdata;
by product;
var ampida;
title1 'ODS Output - with BY Statement';
run;
ods output close;
Later these data sets can be combined by using the macro variable &NAMELIST.
data allmoments;
set &namelist;
run;
The LOG shows.

53
54 data allmoments;
55 set &namelist;
56 run;
NOTE: There were 6 observations read from the data set WORK.MOMENTS.
NOTE: There were 6 observations read from the data set WORK.MOMENTS1.
NOTE: There were 6 observations read from the data set WORK.MOMENTS2.
NOTE: There were 6 observations read from the data set WORK.MOMENTS3.
NOTE: There were 6 observations read from the data set WORK.MOMENTS4.
NOTE: The data set WORK.ALLMOMENTS has 30 observations and 11 variables.

View solution in original post

5 REPLIES 5
Gerd47
Calcite | Level 5

No, use the %let statement to create a macro variable for example.

Best regards,

Gerd

kuridisanjeev
Quartz | Level 8

Hi Gerd47,

i think there is a way...

please go through bellow screen shot,

macro.JPG

Regards..

Sanjeev.K

Hima
Obsidian | Level 7


The MATCHALL= option for the OUTPUT destination on the ODS statement can be used to name a macro variable that will
contain a list of SAS data tables. In the following example a PROC UNIVARIATE is executed with a BY statement. For each
value of the BY variable (PRODUCT) a data set will be created which will contain the summary known as MOMENTS. The
MATCHALL option requests separate data sets and the list of the names of these data sets is to be written to the macro
variable &NAMELIST.
ods output Moments(match_all=namelist)=work.Moments;
proc univariate data=magdata;
by product;
var ampida;
title1 'ODS Output - with BY Statement';
run;
ods output close;
Later these data sets can be combined by using the macro variable &NAMELIST.
data allmoments;
set &namelist;
run;
The LOG shows.

53
54 data allmoments;
55 set &namelist;
56 run;
NOTE: There were 6 observations read from the data set WORK.MOMENTS.
NOTE: There were 6 observations read from the data set WORK.MOMENTS1.
NOTE: There were 6 observations read from the data set WORK.MOMENTS2.
NOTE: There were 6 observations read from the data set WORK.MOMENTS3.
NOTE: There were 6 observations read from the data set WORK.MOMENTS4.
NOTE: The data set WORK.ALLMOMENTS has 30 observations and 11 variables.

Gerd47
Calcite | Level 5

Ah, ok. Didn't know this option.

kuridisanjeev
Quartz | Level 8

Thanks Hima

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1481 views
  • 0 likes
  • 3 in conversation