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

I want to covert a regular code (below)  into a macro that will produce either the frequency report or the descriptive
statistics report based on a value of a parameter that is passed to the macro.*/;

 

Original code

/*frequency report for month*/;
proc means data=VIRGINIAKEY N ; var month; class month;run;
/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/;
proc means data=VIRGINIAKEY ; var  AirTemp; run;


Myy Current trial code:

%macro freq_Describe (MNTH=month AIR_Temp=AirTemp );
/*frequency report for month*/;
proc means data=VIRGINIAKEY N ; var &MNTH.; class &MNTH.;run;
/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/;
proc means data=VIRGINIAKEY ; var &AIR_Temp.; run;
%mend freq_Describe;

%freq_Describe (MNTH=month ; AIR_Temp=AirTemp);

usiing my trial code, I got several errors

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
 
 
NOTE: Line generated by the invoked macro "FREQ_DESCRIBE".
81 proc means data=VIRGINIAKEY ; var &AIR_Temp.; run;
_
22
200
WARNING: Apparent symbolic reference AIR_TEMP not resolved.
 
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, /, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
 
ERROR 200-322: The symbol is not recognized and will be ignored.
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
 
NOTE: Line generated by the macro variable "MNTH".
81 month ; AIR_Temp=AirTemp
________
180
NOTE: Line generated by the macro variable "MNTH".
81 month ; AIR_Temp=AirTemp
________
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
82
83
84 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
96

Any advice will be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

There are at least two problems with your code. You need commas between macro parameters in your MACRO statement and when you call it:

%macro freq_Describe (MNTH=month, AIR_Temp=AirTemp );
/*frequency report for month*/;
proc means data=VIRGINIAKEY N ; var &MNTH.; class &MNTH.;run;
/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/;
proc means data=VIRGINIAKEY ; var &AIR_Temp.; run;
%mend freq_Describe;

%freq_Describe (MNTH=month, AIR_Temp=AirTemp);

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

There are at least two problems with your code. You need commas between macro parameters in your MACRO statement and when you call it:

%macro freq_Describe (MNTH=month, AIR_Temp=AirTemp );
/*frequency report for month*/;
proc means data=VIRGINIAKEY N ; var &MNTH.; class &MNTH.;run;
/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/;
proc means data=VIRGINIAKEY ; var &AIR_Temp.; run;
%mend freq_Describe;

%freq_Describe (MNTH=month, AIR_Temp=AirTemp);
mrahouma
Obsidian | Level 7
@SASKiwi Is there a way to A) add a parameter to the macro that can control which variable is used for the report and 2) add titles that reflect the type of report (frequency or descriptive statistics) including a short
description of the variable (specifying the description of the variable as a parameter for the macro)? Sorry for overloading.
SASKiwi
PROC Star

@mrahouma  - I'm not sure what you mean by "add a parameter to the macro that can control which variable is used for the report". If you could post where this variable would go in your code, then that would make it a lot clearer. Here is an example of adding a title.

 

%macro freq_Describe (MNTH=month, AIR_Temp=AirTemp, MyTitle =  );
/*frequency report for month*/;
proc means data=VIRGINIAKEY N ; var &MNTH.; class &MNTH.;run;
/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/;
proc means data=VIRGINIAKEY ;
title1 "&MyTitle";
 var &AIR_Temp.; run;
%mend freq_Describe;

%freq_Describe (MNTH=month, AIR_Temp=AirTemp, MyTitle = Air Temperatures);
mrahouma
Obsidian | Level 7

Thanks a lot for your follow-up reply. Assuming after preparation of our macro , we need to get one of the two included variable (i.e. month or airTemp only ). Consequently we need to edit the results to convey that. I tried to see if the current macro can give the results of 1 variable  eg month but it doesn't. Any advice will be greatly appreciated.

SASKiwi
PROC Star

Please provide an example of the data you have and the expected output you want.

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
  • 6 replies
  • 693 views
  • 1 like
  • 2 in conversation