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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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