BookmarkSubscribeRSS Feed
UCFtigers2017
Fluorite | Level 6

Below is a simple macro I need to create for an assignment. But I am having an issue that I do not understand. 

 

The data is called homework.cereal and the name of it is assigned to a macro variable &name. It has  a bunch of cereals, the manufacturer of the cereal, 12 numeric variables describing each cereal such as amount of protein, sugar etc. . 

 

The macro needs to be able to take any of the the numeric variables from the data set, for example sugar. And then it needs to create a macro variable for each brand where the value assigned to it is the mean amount of sugar for that brand. 

 

 

Everything in the macro seems to be good except that I keep getting errors that the name of the macro can't have a symbol it it. So it is reading &variable in the first argument of call symput as it is instead of putting in 'sugar'. How do i fix this? 

 

%macro create_macros(variable) ;
title "Means of &variable by Manufacturer" ;
proc means data = &name ;
class manufacturer;
var &variable ;
output out = stats mean = ;
run;
data _null_;
set stats;
call symput("&variable"||manufacturer,&variable);
run;
%mend create_macros;

 

error message : 

 

NOTE: Invalid argument to function SYMPUT('&variable_P'[12 of 25 characters shown],'
144.375') at line 232 column 175.
Manufacturer=Post _TYPE_=1 _FREQ_=8 Sodium=144.375 _ERROR_=1 _N_=6
ERROR: Symbolic variable name &VARIABLE_QUAKEROATS must contain only letters, digits, and
underscores.

6 REPLIES 6
AndrewHowell
Moderator
First thoughts - use symputx instead of symput. This removes any leading & trailing blanks which may be invalidating the macro name.
Kurt_Bremser
Super User

Take a close look at the contents of your manufacturer variable (leading blanks, UTF characters etc), and make sure that your log corresponds to your code. Those single quotes in the log look suspicious.

 

Your code as such is valid, see this example adapted to sashelp.class:

%macro create_macros(variable) ;
title "Means of &variable by Manufacturer" ;
proc means data = &name ;
class sex;
var &variable ;
output out = stats mean = ;
run;
data _null_;
set stats;
call symput("&variable"||sex!!' ',&variable);
run;
%mend create_macros;

%let name=sashelp.class;
%create_macros(weight);

which works.

UCFtigers2017
Fluorite | Level 6
Thank you!
Astounding
PROC Star

Two issues.  First, PROC MEANS should add the NWAY option.  Otherwise, you will need to deal with an additional observation that contains statistics for all manufacturers combined.

 

Second, the program you are showing is not the one you ran.  You ran something more like this:

 

call symput('&variable'||'_'||manufacturer,&variable);

 

The underscore is up to you, but the single quotes are causing the problem.  Switch to double quotes, the way you did for the title statement.  And switching to CALL SYMPUTX can only help by eliminating leading blanks in the values assigned to the macro variables.

 

If you have already made these changes, the problem lies in SAS being able to locate the newest version of the macro.  If that is the problem, the simplest way to solve that is to end the current SAS session and start a new one.

UCFtigers2017
Fluorite | Level 6

Thank you !

AndrewHowell
Moderator
If one of these suggestions helped you fix your problem, please return to this page and select "Accept as Solution" for that suggestion.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 650 views
  • 2 likes
  • 4 in conversation