BookmarkSubscribeRSS Feed
rhaley1821
Obsidian | Level 7

Hi everyone, 

 

I am a newer SAS user and am working on a project that requires me to create macro that creates a histogram with a variety of macros inside. I have created the following code, but although I get no errors or warnings in my log, I get no results. Can anyone help?

 

Thanks so much. 

 

my code: 

 

%MACRO mymacro ( DSNm = , Vbl = , Stats = N MEAN STDDEV ,
Ndec = 1);
TITLE1 "title1";
proc sgplot data = work.&DSNm;
histogram &Vbl/N MEAN STDDEV;
run;
%MEND title2;

%( DSNm = , Vbl = , Stats = N MEAN STDDEV , Ndec = 1);

7 REPLIES 7
rhaley1821
Obsidian | Level 7

my goal is to produce a histogram that looks like this: Screen Shot 2020-12-09 at 11.23.21 PM.png

rhaley1821
Obsidian | Level 7

I got it all running, thanks for the feedback!

SASKiwi
PROC Star

Here is one possible problem. Add spaces like below.

histogram &Vbl / N MEAN STDDEV;  * Add spaces;
ballardw
Super User

@rhaley1821 wrote:

Hi everyone, 

 

I am a newer SAS user and am working on a project that requires me to create macro that creates a histogram with a variety of macros inside. I have created the following code, but although I get no errors or warnings in my log, I get no results. Can anyone help?

 

Thanks so much. 

 

my code: 

 

%MACRO mymacro ( DSNm = , Vbl = , Stats = N MEAN STDDEV ,
Ndec = 1);
TITLE1 "title1";
proc sgplot data = work.&DSNm;
histogram &Vbl/N MEAN STDDEV;
run;
%MEND title2;

%( DSNm = , Vbl = , Stats = N MEAN STDDEV , Ndec = 1);


The code you show does not call the macro at all and I would expect you to get a number of errors from the statement:

%( DSNm = , Vbl = , Stats = N MEAN STDDEV , Ndec = 1);

Best practice when having any question about the results, or lack of results, is to copy the submitted code from the LOG and paste the copied text into a text box opened on the forum with the </> icon. Include the Code, notes, messages and errors for the section in doubt.

 

If you actually properly called the macro using

%mymacro( DSNm = , Vbl = , Stats = N MEAN STDDEV , Ndec = 1);

Then you did not provide a data set name or variable so the code created by this line

proc sgplot data = work.&DSNm;

would resolve to:

proc sgplot data = work. ;

with all sorts of "what data set to use" results.

The line

histogram &Vbl/N MEAN STDDEV;

Would resolve to

histogram    /N MEAN STDDEV;

which if there were a data set available would plot ALL numeric variables.

The Parameter values are placed in the CODE where they macro variable names  are used. If you don't provide a value then nothing appears in the code.

 

 

kbauphealth20
Fluorite | Level 6

I think there is too much information being compiled in different statements.

 

Example:

"proc sgplot data = work.&DSNm;"

should be

"proc sgplot data = &DSNm;"

 

&DSNm is already going to specify a data set, so adding work. to it will mess things up.

 

"histogram &Vbl/N MEAN STDDEV;" is a mouthful of a histogram. A basic histogram shows one variable at a time.

Instead...

"histogram &Vbl;" should be sufficient.

 

Deanna_Payne
Obsidian | Level 7

Don't forget that even in a Macro you need to close off your titles and your subtitles. And you ask SAS to mend title 2 but Mend wouldn't apply to a regular title but to the macro name (i.e. MyMacro)

 

%MACRO mymacro ( DSNm = , Vbl = , Stats = N MEAN STDDEV ,
Ndec = 1);
TITLE1 "title1";
proc sgplot data = work.&DSNm;
histogram &Vbl/N MEAN STDDEV;

title;
run;

TITLE2 "Title2" 

DATA_STEP_HERE

Title;

%MEND Mymacro

 

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1133 views
  • 0 likes
  • 6 in conversation