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))
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;
@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.
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))
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.