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

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
Meteorite | Level 14

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
Meteorite | Level 14

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;

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 761 views
  • 0 likes
  • 3 in conversation