BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gx2144
Calcite | Level 5

%macro ques(n,o);
proc freq data = quad.category1 order = freq;
label Q&n = &o;
tables Q&n/ missing nocum ;
run;

%mend ques;

 

 

%ques(13,'Compared to before COVID-19, your alcohol intake has')
%ques(15,'Before COVID-19, how often did you eat out (at a restaurant) ?' )
%ques(16,'Before COVID-19, how often did you order take-out/delivery?' );
%ques(17,'Before COVID-19, how often did you cook at home?' );
%ques(18,'In the past week, how often have you eaten out?' );
%ques(19,'In the past week, how often have you ordered take-out/delivery' );
%ques(20,'In the past week, how often have you cooked at home?');
%ques(21,'In the past week, how has stress impacted your appetite?' );
%ques(27,'Has there been a change in your anxiety levels compared to before COVID-19?' );
%ques(28,'In the past week, you have felt joyful, cheerful, or optimistic' );
%ques(29,'In the past week, you have felt anxious, irritable, or tense' );
%ques(30,'In the past week, you have felt depressed, hopeless, or trapped' );
%ques(33,'Are you worried you will get sick with Coronavirus?' );
%ques(36,'Are you worried that a loved one will get sick with the Coronavirus?' );
%ques(39,'What is your sex?' );
%ques(46,'What is your age?' );
%ques(47,'In what type of community did you live before COVID-19?' );
%ques(48,'In what type of community do you live right now, during COVID-19?' );
%ques(49,'What is your total household income?' );
%ques(50,'What country do you reside in now?' );
%ques(52,'What state do you reside in right now?' );
%ques(54,'How long have these measures (shelter/stay in place, quarantine/isolation, curfew, social distancing) been in place?' );
%ques(55,'Are you following these measures?' );
%ques(57,'Which of the following best describes your living situation before COVID-19?' );
%ques(58,'Which of the following best describes your living situation right now, during COVID-19?' );
%ques(59,'How many individuals currently (and temporarily) live in your current place of residence, including yourself?' );
%ques(60,'How many children under the age of 18 live in your current place of residence?' );
%ques(61,'How many people over the age of 65 live in your current place of residence?' );
%ques(62,'Which of the following best describes your current relationship status?' );
%ques(63,'Which of the following categories best describes your employment status right now?' );
%ques(65,'Are you working remotely?' );
%ques(66,'How often have you gone outside in the past week?' );
%ques(67,'Before COVID-19, I exercised?' );
%ques(68,'During the COVID-19 pandemic, I exercise' );
%ques(69,'Compared to before COVID-19, I have?' );
%ques(70,'What is the highest level of education you have completed?' );
%ques(109,'What is the highest level of education you have completed?' );

 

 

Only the first %ques(13,'Compared to before COVID-19, your alcohol intake has') could run; The rest of the calls could not run. Can anybody help me out?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I am wondering why you think you need a macro in the first place.

You would likely be much better of by making the labels permanent in the data or providing one label statement in the proc freq code.

One of the unfortunate things with working with macro code is that some types of logic errors can cause problems such as making following code not run because something is unstable and if you likely have to restart your SAS session to do almost anything. Save code before closing down though.

Variable lists make calling multiple variables in a tables statement easy.

When code misbehaves it is a good idea to copy the code submitted along with all notes, warnings and errors for the bit that misbehaves and show us that in a code box opened on the forum with the </> icon to preserve formatting of any diagnostics.

 

proc freq data = quad.category1 order = freq;
tables q13 q15-q21 q27-q30 q33 q36
   q39 q46-q50 q52 q54 q55 q57-q63 
   q65-q70 q109;
/ missing nocum ;
label
q13='Compared to before COVID-19= your alcohol intake has'
q15='Before COVID-19= how often did you eat out (at a restaurant ?'
q16='Before COVID-19= how often did you order take-out/delivery?'
q17='Before COVID-19= how often did you cook at home?' 
q18='In the past week= how often have you eaten out?' 
q19='In the past week= how often have you ordered take-out/delivery' 
q20='In the past week= how often have you cooked at home?'
q21='In the past week= how has stress impacted your appetite?' 
q27='Has there been a change in your anxiety levels compared to before COVID-19?' 
q28='In the past week= you have felt joyful= cheerful= or optimistic' 
q29='In the past week= you have felt anxious= irritable= or tense' 
q30='In the past week= you have felt depressed= hopeless= or trapped' 
q33='Are you worried you will get sick with Coronavirus?' 
q36='Are you worried that a loved one will get sick with the Coronavirus?' 
q39='What is your sex?' 
q46='What is your age?' 
q47='In what type of community did you live before COVID-19?' 
q48='In what type of community do you live right now= during COVID-19?' 
q49='What is your total household income?' 
q50='What country do you reside in now?' 
q52='What state do you reside in right now?' 
q54='How long have these measures (shelter/stay in place= quarantine/isolation= curfew= social distancing been in place?' 
q55='Are you following these measures?' 
q57='Which of the following best describes your living situation before COVID-19?' 
q58='Which of the following best describes your living situation right now= during COVID-19?' 
q59='How many individuals currently (and temporarily live in your current place of residence= including yourself?' 
q60='How many children under the age of 18 live in your current place of residence?' 
q61='How many people over the age of 65 live in your current place of residence?' 
q62='Which of the following best describes your current relationship status?' 
q63='Which of the following categories best describes your employment status right now?' 
q65='Are you working remotely?' 
q66='How often have you gone outside in the past week?' 
q67='Before COVID-19= I exercised?' 
q68='During the COVID-19 pandemic= I exercise' 
q69='Compared to before COVID-19= I have?' 
q70='What is the highest level of education you have completed?' 
q109='What is the highest level of education you have completed?' 
;

Loading the same data set multiple times like this is very inefficient.

And are you sure the labels for Q70 and Q109 are correct?

View solution in original post

17 REPLIES 17
novinosrin
Tourmaline | Level 20

Does proc freq really have a label (label Q&n = &o) statement?

 

I am learning something new 

Tom
Super User Tom
Super User

@novinosrin wrote:

Does proc freq really have a label (label Q&n = &o) statement?

 

I am learning something new 


The label statement can be used in any proc or data step that uses datasets.

novinosrin
Tourmaline | Level 20

Ah I see. Thank you Sir @Tom 

gx2144
Calcite | Level 5

Yes it does have label statement.

Reeza
Super User

Please provide more details. What didn't run? Did you get an error? Did you run the macro code with the debugging options and if you did, what did you get?

If not, run your macro with the debugging options and see what errors are generated. Post the code and full log back and someone can help you debug it.

Macro debugging options:

options mprint symbolgen;

 

Spoiler

@gx2144 wrote:

%macro ques(n,o);
proc freq data = quad.category1 order = freq;
label Q&n = &o;
tables Q&n/ missing nocum ;
run;

%mend ques;

 

 

%ques(13,'Compared to before COVID-19, your alcohol intake has')
%ques(15,'Before COVID-19, how often did you eat out (at a restaurant) ?' )
%ques(16,'Before COVID-19, how often did you order take-out/delivery?' );
%ques(17,'Before COVID-19, how often did you cook at home?' );
%ques(18,'In the past week, how often have you eaten out?' );
%ques(19,'In the past week, how often have you ordered take-out/delivery' );
%ques(20,'In the past week, how often have you cooked at home?');
%ques(21,'In the past week, how has stress impacted your appetite?' );
%ques(27,'Has there been a change in your anxiety levels compared to before COVID-19?' );
%ques(28,'In the past week, you have felt joyful, cheerful, or optimistic' );
%ques(29,'In the past week, you have felt anxious, irritable, or tense' );
%ques(30,'In the past week, you have felt depressed, hopeless, or trapped' );
%ques(33,'Are you worried you will get sick with Coronavirus?' );
%ques(36,'Are you worried that a loved one will get sick with the Coronavirus?' );
%ques(39,'What is your sex?' );
%ques(46,'What is your age?' );
%ques(47,'In what type of community did you live before COVID-19?' );
%ques(48,'In what type of community do you live right now, during COVID-19?' );
%ques(49,'What is your total household income?' );
%ques(50,'What country do you reside in now?' );
%ques(52,'What state do you reside in right now?' );
%ques(54,'How long have these measures (shelter/stay in place, quarantine/isolation, curfew, social distancing) been in place?' );
%ques(55,'Are you following these measures?' );
%ques(57,'Which of the following best describes your living situation before COVID-19?' );
%ques(58,'Which of the following best describes your living situation right now, during COVID-19?' );
%ques(59,'How many individuals currently (and temporarily) live in your current place of residence, including yourself?' );
%ques(60,'How many children under the age of 18 live in your current place of residence?' );
%ques(61,'How many people over the age of 65 live in your current place of residence?' );
%ques(62,'Which of the following best describes your current relationship status?' );
%ques(63,'Which of the following categories best describes your employment status right now?' );
%ques(65,'Are you working remotely?' );
%ques(66,'How often have you gone outside in the past week?' );
%ques(67,'Before COVID-19, I exercised?' );
%ques(68,'During the COVID-19 pandemic, I exercise' );
%ques(69,'Compared to before COVID-19, I have?' );
%ques(70,'What is the highest level of education you have completed?' );
%ques(109,'What is the highest level of education you have completed?' );

 

 

Only the first %ques(13,'Compared to before COVID-19, your alcohol intake has') could run; The rest of the calls could not run. Can anybody help me out?


 

gx2144
Calcite | Level 5


341
342 /*frequency table for fategorical data*/
343 options mprint symbolgen;
344 %macro ques(n,o);
345 proc freq data = quad.category1 order = freq;
346 label Q&n = &o;
347 tables Q&n/ missing nocum ;
348 run;
349
350 %mend ques;
351
352 %ques(13,'Compared to before COVID-19, your alcohol intake has')
MPRINT(QUES): proc freq data = quad.category1 order = freq;
SYMBOLGEN: Macro variable N resolves to 13
SYMBOLGEN: Macro variable O resolves to 'Compared to before COVID-19, your alcohol intake has'
MPRINT(QUES): label Q13 = 'Compared to before COVID-19, your alcohol intake has';
SYMBOLGEN: Macro variable N resolves to 13
MPRINT(QUES): tables Q13/ missing nocum ;
MPRINT(QUES): run;

NOTE: Writing HTML Body file: sashtml.htm
NOTE: There were 588 observations read from the data set QUAD.CATEGORY1.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.13 seconds
cpu time 0.10 seconds


353 %ques(15,'Before COVID-19, how often did you eat out (at a restaurant) ?' 乯
354 %ques(16,'Before COVID-19, how often did you order take-out/delivery?' 乯;
SYMBOLGEN: Macro variable N resolves to 18
355 %ques(17,'Before COVID-19, how often did you cook at home?' 乯;
SYMBOLGEN: Macro variable O resolves to 'In the past week, how often have you eaten out?'
SYMBOLGEN: Macro variable N resolves to 18
356 %ques(18,'In the past week, how often have you eaten out?' );
SYMBOLGEN: Macro variable N resolves to 19
SYMBOLGEN: Macro variable O resolves to 'In the past week, how often have you ordered take-out/delivery'
SYMBOLGEN: Macro variable N resolves to 19
357 %ques(19,'In the past week, how often have you ordered take-out/delivery' );

 

 

here is the log.Thanks

smantha
Lapis Lazuli | Level 10

can you provide the log please. My hunch is around the line 

label Q&n = &o;

change it to label Q&n = "&o";

Reeza
Super User

@smantha  Shouldn't be the issue as they're passing the strings in as quoted. Unless the string has an extra quote somewhere, which isn't shown in the code posted. 

 

 

gx2144
Calcite | Level 5

I do not think that is the problem because I have used the same macro before in another program and that worked very well. 

But thanks anyway.

Reeza
Super User
Restart your system and run it again and see if you have issues. And add semicolons to the end of each macro code. You're using another language and I've seen the Chinese keyboard setting cause issues in SAS programs before...unfortunately.
Reeza
Super User
Also, why the multiple calls, you can call them all at once and should ideally apply your labels to your main data set rather than each one manually. Then they exist for any proc to use and you do not need a macro at all.

proc freq data = ....;
table q13 q15-q21 q27-q30 .... / missing nocum;
run;
gx2144
Calcite | Level 5

I think I can try without the macro. 

novinosrin
Tourmaline | Level 20

Hi @gx2144  Can you plz try macro quoting the second parameter with %bquote and execute?

 

%ques(15,%bquote('Before COVID-19, how often did you eat out (at a restaurant) ?') )
smantha
Lapis Lazuli | Level 10

Do you know why there are special characters in your log? one of the quoting functions as suggested by novinosrin might help. If you are just getting counts and description you can use a format and proc means or proc summary to get all the information in a single go.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 1670 views
  • 0 likes
  • 6 in conversation