BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TingSern
Obsidian | Level 7

Hello,

 

I have input data that looks like these -

 

Size         Space     Date

840K        7%          2017.183

23433K    25%        2013.034

 

The "K" probably is 1000 or 1024 - I take the value as 1000.  

 

I have not seen any INFORMATS that can convert 840K to 840000 (numeric value) or 7% to 0.07 (numeric value).  The date has a "." in between the year and day (in Julian format).  I need to convert the date to SAS internal date.  Again, I went looking at the INFORMATS available - but, I can't see any suitable ones. 

 

I understand the coding required (for example) - 

 

SIZEN = INPUT (SIZE. informat); 

 

It is trying to look for a proper informat that gives me the problems. 

 

Thank you.

TS

1 ACCEPTED SOLUTION

Accepted Solutions
TingSern
Obsidian | Level 7

Yes - this is the right solution.  Thank you.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
data want;
infile cards firstobs=2;
format size 10. space 7.2 date date9.;
input size_string $ space :percent7. date_string :$10.;
date = input(compress(date_string,'.'),julian8.);
pos = notdigit(trim(size_string));
size = input(substr(size_string,1,pos-1),10.);
select (substr(size_string,pos,1));
  when ('K') size = size * 1024;
end;
drop size_string date_string pos;
cards;
Size         Space     Date
840K        7%          2017.183
23433K    25%        2013.034
;
run;

You just have to "fit" the data for the proper formats. How eg the input for the JULIANw. format has to look can be taken from the documentation.

The documentation can usually be found by googling "SAS 9.4" and the keyword, or something like "SAS 9.4 informats by category".

TingSern
Obsidian | Level 7

Yes - this is the right solution.  Thank you.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

In future, please mark the appropriate post as the correct answer, not your reply to it.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, the first is simple:

sizen=input(tranwrd(size,"Z","000"),best.);

The date:

new_date=input(compress(date,"."),julian7.);

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 514 views
  • 0 likes
  • 3 in conversation