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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.