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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

1 REPLY 1
ballardw
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 451 views
  • 0 likes
  • 2 in conversation