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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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