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

Hi Everyone, 

 

Been learning for about a week. So, i have a data set that follows the following pattern:

rank (numeric), company ($), country ($), sales (num), profits (num), assets (num), market value (num)

 

the data under the last 4 numeric variables are presented in billions of dollars, as "$1.5B" or "$200.1B", and vary in length 

 

Im using the following code:

DATA bigcos;
INFILE 'C:\Users\dlobsien\Documents\bigcompanies.txt';
INPUT ranking company_name $26. +1 country $18. sales_in_billions :dollar10. profits_in_billions :dollar10. assets_in_billions :dollar10. +1 profits_in_billions :dollar10.;
title companies data;
RUN;

——————————-

PROC PRINT data=bigcos (obs=15);
Run;

 

the first three variables go in fine, but it wont read anything after that with the Bs in the way (i assume that's the issue). whenever i add a line that says "compress(var, 'B')", after the input lines it gives me 0 observations—maybe I'm entering the syntax wrong or putting it in the wrong spot. 

 

I've also included the data set in case that is useful.

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

https://communities.sas.com/t5/SAS-Programming/How-do-I-properly-use-PROC-IMPORT-for-a-multi-spaced-...

 

Classmates?

 

You need to write your own informat preferably but you could also just read it as a character, remove the B and then convert it to billions. 

 

https://www.lexjansen.com/pharmasug/2005/posters/po06.pdf

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

You mentioned that the values vary in length, but it does not look that way when I viewed your attached text file using this websites viewer tool.  The values of a given field are always in the same location on the line.

 

Why not just skip that column in your INPUT statement. Looks like you already know how to skip a column since you have included the +1 cursor movement command in your current INPUT statement.

If the value is not always a B then read it as another character variable and then you can write a program to adjust the magnitude of the number read based on what letter was appended.

 

Hint: You don't want to use the : modifier on your informats.  That will switch your input statement from formatted mode to list mode.

Damon1
Obsidian | Level 7

yeah, I'm not actually sure how to use the +1. i added on a whim it because i noticed it in a textbook, and added it one at a time because I think made the character variables read.

 

the data under the last 4 numeric variables vary from as short as $4.9B to as long as $2,265.8B, and each observation for those variables ends in "B"

Tom
Super User Tom
Super User
Include the leading spaces when counting how many characters the field takes. So if the field before the one with B in it ends in column 20 and the B is in column 30 then use COMMA9. informat to read the 9 characters in columns 21 to 29.
... @21 number comma9. letter $1. ...
Reeza
Super User

https://communities.sas.com/t5/SAS-Programming/How-do-I-properly-use-PROC-IMPORT-for-a-multi-spaced-...

 

Classmates?

 

You need to write your own informat preferably but you could also just read it as a character, remove the B and then convert it to billions. 

 

https://www.lexjansen.com/pharmasug/2005/posters/po06.pdf

Damon1
Obsidian | Level 7

probably—its an online class so i couldnt tell you lmao.

 

i imported it as a character, then compressed out the $ and B then made a new data set and wrote varname=import(oldvar, best.)

 

and that worked well enough

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1284 views
  • 3 likes
  • 3 in conversation