BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
miss2223
Fluorite | Level 6

Hi I would like to add an additional calculation to replace the current date in the dataset -  'CON_DATE_START = min(PL_DATE_START, SS_DATE_START);'

 

The original code is below: I am aware I cannot add variables/calculation to the proc sort step. I have tried to add an extra data step above the sort step, but then the final step of %if(length) is a macro variable linking to the step from the proc sort. Which my datastep will not work considering it returns to a normal output rather than a macro output. Could you please advise how I can add a macro variable step to add the calculation in.  Many Thanks! 

 


proc sort
data=&lib..&customersdetail
out=_&customersdetail;
where also ANLAGE eq "&anlage";
run;

 

%if %length(&anlage) %then _&customersdetail;
%else &lib..&customersdetail;
(rename=(DONOTBUY=_DONOTBUY)
where=(_DONOTBUY is missing))

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

The proc sort and following code non-valid sas code.

 

You can just insert another data step:

data want;
  set have;

  con_start_date = min(pl_date_start, ss_date_start);
run;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

@miss2223 wrote:

 

%if %length(&anlage) %then _&customersdetail;
%else &lib..&customersdetail;
(rename=(DONOTBUY=_DONOTBUY)
where=(_DONOTBUY is missing))


Unfortunately i don't understand what you are trying to do. I would be easier, if you post the data you have, the expected output and explain the rules that you want applied.

miss2223
Fluorite | Level 6


Original data is &lib..&customersdetail
data original_data;
input var1$ CON_DATE_START PL_DATE_START SS_DATE_START;
datalines;
A 12/12/2008 11/01/2022 05/10/2007
B 19/01/2001 11/02/2008 01/03/2020
C 23/10/2008 02/08/2019 02/02/2010
D 01/09/2002 01/01/2000 19/03/2006;
run;

I want to replace the current CON_DATE_START, instead of that to use calculation CON_DATE_START = min(PL_DATE_START, SS_DATE_START)
Expecting to see:
var1 CON_DATE_START PL_DATE_START SS_DATE_START
A 05/10/2007 11/01/2022 05/10/2007
B 11/02/2008 11/02/2008 01/03/2020
C 02/02/2010 02/08/2019 02/02/2010
D 01/01/2000 01/01/2000 19/03/2006

Because the next step is in macro, I dont know how to link my replacement calculation of CON_DATE_START, so I dont need to change anything to below.

proc sort
data=&lib..&customersdetail
out=_&customersdetail;
where also ANLAGE eq "&anlage";
run;

%if %length(&anlage) %then _&customersdetail;
%else &lib..&customersdetail;
(rename=(DONOTBUY=_DONOTBUY)
where=(_DONOTBUY is missing))

andreas_lds
Jade | Level 19

The proc sort and following code non-valid sas code.

 

You can just insert another data step:

data want;
  set have;

  con_start_date = min(pl_date_start, ss_date_start);
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 545 views
  • 0 likes
  • 2 in conversation