06-23-2016 02:51 PM - edited 06-23-2016 02:52 PM
I'm having a difficult time doing something that I figured would be pretty simple. I need to conver a date to date9. format, which I've done successfully in a data step. However, in that data step I throw my date into a macro variable, at which point its formatting is completely lost. What should I do? The 5 digit SAS date is no good for me.
44 data _null_; 45 curDate= today(); 46 sunday = intnx('week1.1',curDate,-1,'Begin'); 47 saturday = intnx('week1.1',curDate,-1,'End'); 48 format _all_ date9.; 49 put (_all_)(=/); 50 call symput('sunday',sunday); 51 call symput('saturday',saturday); 52 53 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 50:23 51:25 curDate=23JUN2016 sunday=12JUN2016 saturday=18JUN2016 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 54 %PUT &sunday; 20617 <----THIS??? WHY WHY WHY WHY????
06-23-2016 03:21 PM
06-23-2016 03:19 PM
The NOTEs are your first clue: call symput only accepts arguments of type character, so the numeric date value needs to be converted. Since assigned formats are only applied during display (in procedures that create output, or when using the put statement), you get the raw value (days since 01/01/1960).
06-23-2016 03:21 PM
06-24-2016 04:17 AM
Just to add to @KurtBremser's excellent answer, Dates are not real things. It is a representation of number of days since a given timepoint (in this instance). This is one reason why I would never - unless there there was a very good reason - put "data" items in macro language - which is basically a text generator. You will find that doing anything to that data item is so much more difficult - having to convert it process back to macro etc. it always ends in a mess. Why can you not keep your "data" in a "data"set?
06-24-2016 06:25 AM
06-24-2016 06:27 AM
Just to add to @RW9s post:
I would not keep a list of date values in (a) macro variable(s), but rather in a dataset, from which I could create a format, do a series of call executes and the like.
But a single date value (eg a cutoff date for processing) that is repeatedly used in steps (eg where conditions) can reasonably be stored in a macro variable. In this case, it does not matter if it is just a raw 5-digit number, as the conditions will work well with that.
Need further help from the community? Please ask a new question.