An Idea Exchange for SAS software and services

Comments
by Super User
on ‎08-19-2015 10:03 AM

Hi,

Its a nice idea, and maybe in your particular coding one way of doing things, however I am afraid its a no from from me on several levels.


Firstly in your code you have assumed that mon/yr dates will be assumed to be 01.  This is your interpretation of missing data, and is not a general consensus.   


Secondly, why do we need these macros?  There are perfectly functioning functions = mdy, and input which are designed to handle conversions.  How you substring that out is a very case specific item.


Thirdly, how do you know that 0615 is a date? 


Finally, the code as is cannot be used as a inline function, only a separate call.  This will not be useful in all situations, say I am pulling a big dataset, I don't want a datastep call for each date variable.  By inline I mean:

%macro do_something (var=);

     %local ret_var;

     %let retvar=&var.;

     &retvar.

%mend do_something;

(note not tested!)  The point here is that the macro code resolves itself to a return value and can be used in normal code:

data ...;

     set ...;

     my_new_variable=%do_something(var=old_var);

run;

Finally, all 5 macro's above could be folded down into one, which has the date format passed in as a parameter:

%macro Convert (...,var_fmt=yymmdd10);

Then you could change var_fmt to be yymm8 or mmyy4 etc.  This mimics the SQL variant TO_DATE: Oracle/PLSQL: TO_DATE Function

by New Contributor Koti
on ‎08-20-2015 05:02 AM

Firstly in your code you have assumed that mon/yr dates will be assumed to be 01.  This is your interpretation of missing data, and is not a general consensus.  --->We can take these macros and can use as per requirement.Mostly date may require either first 01 day of month or last day of month(30 or 31).There can be a flexibility to modify day value as per requirement.

Secondly, why do we need these macros?  There are perfectly functioning functions = mdy, and input which are designed to handle conversions.  How you sub string that out is a very case specific item.--->mdy is works for numeric value but if you have value like Jul or July , mdy will not read .We need to look for some other option , so I used substr.

Thirdly, how do you know that 0615 is a date? ---->The developer should aware of which column do we need to modify.

I am agree with you but these macros may use for many developers who actually can use as per there "Date modification" requirement.

Idea Statuses
Top Liked Authors