Hi there,
I want to take a subset from a data using macro variable but getting an error. I am interested to get table "WANT" using macro. Thank you in advance for your kind guidance.
data have;
length id $3 submission_date $8;
input id submission_date ;
datalines;
101 20110101
102 20110202
103 20110303
104 20120101
105 20120202
106 20120303
107 20130101
108 20130202
109 20130303
;
run;
data have1;
set have (rename =submission_date=submission_date1);
submission_date=input(put(submission_date1, $8.), yymmdd8.);
format submission_date date9.;
drop submission_date1;
run;
data want;
set have1;
if submission_date ge '01JAN2011'd and submission_date le '31DEC2011'd;
run;
%macro annual_subset(year);
data have2;
set have1;
if submission_date ge '01JAN&year.'d and submission_date le '31DEC&year.'d;
run;
%mend;
%annual_subset(2011)
use double quotes
if submission_date ge "01JAN&year"d and submission_date le "31DEC&year."d;
Macro variables will not resolve within single quotes.
use double quotes
if submission_date ge "01JAN&year"d and submission_date le "31DEC&year."d;
Macro variables will not resolve within single quotes.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.