BookmarkSubscribeRSS Feed
docctong
Fluorite | Level 6

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.  

3 REPLIES 3
mkeintz
PROC Star

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

--------------------------
Kurt_Bremser
Super User

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.

Reeza
Super User

@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. 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3330 views
  • 2 likes
  • 4 in conversation