DATA Step, Macro, Functions and more

Creating a Macro variable By using ODS

Accepted Solution Solved
Reply
Super Contributor
Posts: 276
Accepted Solution

Creating a Macro variable By using ODS

Hi every one...

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

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

Thanks

Sanjeev.k


Accepted Solutions
Solution
‎04-02-2012 08:46 AM
Regular Contributor
Posts: 233

Creating a Macro variable By using ODS


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


All Replies
Occasional Contributor
Posts: 10

Creating a Macro variable use ODs

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

Best regards,

Gerd

Super Contributor
Posts: 276

Creating a Macro variable By using ODS

Hi Gerd47,

i think there is a way...

please go through bellow screen shot,

macro.JPG

Regards..

Sanjeev.K

Solution
‎04-02-2012 08:46 AM
Regular Contributor
Posts: 233

Creating a Macro variable By using ODS


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.

Occasional Contributor
Posts: 10

Creating a Macro variable By using ODS

Ah, ok. Didn't know this option.

Super Contributor
Posts: 276

Creating a Macro variable By using ODS

Thanks Hima

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 280 views
  • 0 likes
  • 3 in conversation