DATA Step, Macro, Functions and more

create a parameter of a date value

Accepted Solution Solved
Reply
Highlighted
Regular Contributor
Posts: 199
Accepted Solution

create a parameter of a date value

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;


Accepted Solutions
Solution
‎04-16-2018 06:47 AM
PROC Star
Posts: 1,400

Re: create a parameter of a date value

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

View solution in original post


All Replies
Regular Contributor
Posts: 199

Re: create a parameter of a date value

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;

PROC Star
Posts: 1,400

Re: create a parameter of a date value

I get no errors from running the code.

 

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

Regular Contributor
Posts: 199

Re: create a parameter of a date value

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

Solution
‎04-16-2018 06:47 AM
PROC Star
Posts: 1,400

Re: create a parameter of a date value

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

Super User
Super User
Posts: 9,840

Re: create a parameter of a date value

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 129 views
  • 0 likes
  • 3 in conversation