- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a question on what is the purpose of using input and put functions together in the command below:
Inc_date=input(put(var14,8.),yymmdd8.);
Var14 is in a CSV file that I am importing into SAS. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The outer function
INPUT(x,yymmdd8.);
tells sas to expect X to be a character variable with 8 characters laid out as YYYYMMDD, and by applying the YYMMDD8. informat, to convert it to a date value (i.e. number of days after/before 01jan1960), making INC_DATE a date variable.
But VAR14 is apparently a numeric, not a character var. It may very well have a numeric value like 20170929, but the INPUT function needs it to be "20170920" to properly convert. Therefore the nested function, PUT(var14,8.), tells sas to "write out" the value of var14 as a character variable length 8.
One could do the equivalent by:
dat=mdy(mod(int(x/100),100),mod(x,100),int(x/10000));
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
put() converts a numerical value to a string, which is then converted to a date value with the input() function.
Probably var14 contains a numerical value like 20170929.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@docctong wrote:
I have a question on what is the purpose of using input and put functions together in the command below:
Inc_date=input(put(var14,8.),yymmdd8.);
Var14 is in a CSV file that I am importing into SAS. Thanks.
Ideally it would be read in correctly in the first place, not converting after, using the informat of yymmdd8 rather than using PROC IMPORT. There are circumstances where this may not be appropriate though.