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

Hello

I am trying to create a parameter of a date value and  use it to take all rows with date higher than  01Apr2017.

Can anyone please explain why it is not working and what is the correct code?

Thanks  a lot

 

data aaa;
length LOC_ID $8 Date Demand 8;
LOC_ID = "C1";
demand = 0;
do Date = '01JAN2017'd to '30JUN2017'd;
output;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Also, your second data step is redundant. Simple use the FORMAT Statement in your first data step.

View solution in original post

5 REPLIES 5
Ronein
Onyx | Level 15

sorry.Here is the code.Why is it no working?

 

 

data aaa;
length LOC_ID $8 Date Demand 8;
LOC_ID = "C1";
demand = 0;
do Date = '01JAN2017'd to '30JUN2017'd;
output;
end;
run;


data bbb;
set aaa;
format Date date9.;
run;

%let monParam='01Apr2017'd;
Data Want;
SET bbb;
IF Date>&monParam.;
Run;

PeterClemmensen
Tourmaline | Level 20

I get no errors from running the code.

 

Please post your log and what yoy consider "not working".

Ronein
Onyx | Level 15

Sorry.You are right. I run  it again and it is working.Thank you anyway

PeterClemmensen
Tourmaline | Level 20

Also, your second data step is redundant. Simple use the FORMAT Statement in your first data step.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please define "not working".  After tidying up your code and dropping the unnecessary datastep the code works perfectly:

data aaa;
  length loc_id $8 date demand 8;
  loc_id="C1";
  demand=0;
  do date='01JAN2017'd to '30JUN2017'd;
    output;
  end;
  format date date9.;
run;

%let monparam='01Apr2017'd;
data want;
  set aaa;
  if date > &monParam.;
run;
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
  • 5 replies
  • 2018 views
  • 0 likes
  • 3 in conversation