Hello,
I am trying to find maximum value from all dates variable which is present in Macro variable" &dates. ". Can someone help me how to find Maximum value from this all dates. I convert all dates in date9. format by using following code. I wrote following code to find maximum value but it gives me error message.
Any help will be appreciated .
Thank you in Advance.
**************************** DATA SET STATEMENT ***********************
data now;
set nn;
format &dates date9.;
informat &dates date9.;
where Subject^='';
run;
proc sort data=now out=new_; by subject; run;
data ll;
set now_;
date1=max(&dates);
format date1 date9.;
run;
******************* LOG ERROR MESSAGE *********************************
ERROR: File WORK.NOW_.DATA does not exist.
35 date1=max(&dates);
NOTE: Line generated by the macro variable "DATES".
35 EGDT EGDT_AT6 EXEGDT LSTSMKDT ACCUDT ASESDT CNTRDT EDSSDT EVALDT EXAMDT HPTEVLDT PFDT PFMKDT PFTDT SDMTASDT DSDT PGNDT
________
388
76
35 ! LBDT PEDT PEASSDT ESSDT HADSDT PWCDT SUICDT QUEDT VSDT VSNDT MRIDT AESTDT AEENDT VISDT CMSTDT1 CMENDT1 ENSYMDT MSRLDT
35 ! RELAPDT STSYMDT
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored.
First thing is fix errors:
proc sort data=now out=new_; by subject; run; data ll; set now_; date1=max(&dates); format date1 date9.; run;
The second data step did not reference the sorted data.
Second the data step MAX function wants variable names to be comma delimited:
y = max(a, b, c);
If you do not know how many variables you are using then likely an array would be easier
data ll; set new_; array d__ &dates.; date1=max(of d__(*)); format date1 date9.; run;
I used a name like d__ for the array as I have no idea what other variables you may have and didn't want a complaint about an error generated because the array name I picked matched an existing variable. If you have a variable named d__ then change the references above to something NOT in your data.
First thing is fix errors:
proc sort data=now out=new_; by subject; run; data ll; set now_; date1=max(&dates); format date1 date9.; run;
The second data step did not reference the sorted data.
Second the data step MAX function wants variable names to be comma delimited:
y = max(a, b, c);
If you do not know how many variables you are using then likely an array would be easier
data ll; set new_; array d__ &dates.; date1=max(of d__(*)); format date1 date9.; run;
I used a name like d__ for the array as I have no idea what other variables you may have and didn't want a complaint about an error generated because the array name I picked matched an existing variable. If you have a variable named d__ then change the references above to something NOT in your data.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.