I am looking to create a macro that could show me statistics for new cases when I enter in the month and the country but it doesn't work.
data mylib_d3.covid_data;
run;
%MACRO proc_univariate_means_print(data,var1);
title ---Résumé statistiques_1---;
PROC UNIVARIATE data=&data;
CLASS &mois &pays
VAR &var1 ;
RUN;
title ---Résumé statistiques_2---;
PROC MEANS data=&data mean min max;
VAR &var1;
BY &mois &pays
RUN;
title --- Afficher les observations ---;
PROC PRINT data=&data;
VAR &var1;
RUN;
%MEND;
%LET mylist=nouveaux_cas mois pays
%proc_univariate_means_print(mylib_d3.covid_data, &mylist);
@Feksan wrote:
I am looking to create a macro that could show me statistics for new cases when I enter in the month and the country but it doesn't work.
data mylib_d3.covid_data;
run;
....
If your program really does start with:
data mylib_d3.covid_data;
run;
then you will have overwritten mylib_d3.covid_data with an empty data set. I believe your log will say:
NOTE: The data set MYLIB_D3.COVID_DATA has 1 observations and 0 variables.
Even if the syntax of the rest of your code is correct, you will see no data reports.
More generally
but it doesn't work.
provides us with no information to diagnose or prescribe. Please show the log, tell us what you expected to see, and what you did see.
Help us help you.
Congratulations, with this step
data mylib_d3.covid_data;
run;
you have successfully destroyed your source data. The dataset will now contain 1 observation and 0 variables.
In addition to destroying your data, this program contains basic syntax errors.
A BY statement must end with a semicolon.
A CLASS statement must end with a semicolon.
A good rule of thumb is to get your program working without macros first, and then try to convert it to a macro. It's too difficult for a beginner to debug if you have to figure out whether your error comes from SAS language or macro language.
@Astounding wrote:
A good rule of thumb is to get your program working without macros first, and then try to convert it to a macro. It's too difficult for a beginner to debug if you have to figure out whether your error comes from SAS language or macro language.
This is so important, I am going to repeat it.
"A good rule of thumb is to get your program working without macros first, and then try to convert it to a macro. It's too difficult for a beginner to debug if you have to figure out whether your error comes from SAS language or macro language."
If you can't get the code to work without macros and without macro variables, then it will never work when you use macros and macro variables.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.