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

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)
Swain
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 804 views
  • 0 likes
  • 2 in conversation