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

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!

SAS Enterprise Guide vs. SAS Studio

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.

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