Put and Input Functions

Reply
Occasional Contributor
Posts: 11

Put and Input Functions

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.  

Trusted Advisor
Posts: 1,145

Re: Put and Input Functions

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));

Super User
Posts: 8,589

Re: Put and Input Functions

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 21,481

Re: Put and Input Functions


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. 

Ask a Question
Discussion stats
  • 3 replies
  • 158 views
  • 2 likes
  • 4 in conversation