BookmarkSubscribeRSS Feed
Feksan
Fluorite | Level 6

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);

4 REPLIES 4
mkeintz
PROC Star

@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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kurt_Bremser
Super User

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.

Astounding
PROC Star

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 1125 views
  • 1 like
  • 5 in conversation