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.
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));
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.
@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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.