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

Hi,

 

I wanted to apply multiple informats to a single variable that is "Salary". The value is like-  $25,000.50 

I am trying to import a fixed length rawfile using infile statement. The length range of this value is 1-15. How to write the input code for this? 

 

This is how I did for single informat value -

 

Input Name$ 1-11 City$ 13-31 / @1 Salary:comma. Subject$ 17-23;
run;

 

Just to make it clear, there are split observation lines in my file and salary starts at 1 and end at 15.

 

Many thanks for your answers.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like your data is in fixed column locations.  To use an INFORMAT with fixed column data you need to specify the width in the INFORMAT value rather than using column ranges.

input
   Name $ 1-11 City $ 13-31 
 / @1 Salary comma15. Subject $ 17-23
;

Note that to read numeric data that contains both $ and commas you can just use the COMMA informat. It will strip out the $ and the commas and then read the result like a normal number.  Also do NOT add a decimal part to the INFORMAT unless your source data has deliberately not included the period and you want to tell SAS where to assume the period should be.  If you read '1234' using 4.2 informat it will read it as 12.34 instead of 1,234.

 

If you want to display the result using the $ then you need to attach the DOLLAR format to the variable using a FORMAT statement.

 

 

View solution in original post

6 REPLIES 6
gauthamk28
Obsidian | Level 7

Could you provide an example of how your raw data file looks like

 

I hope this might sove your problem 

 

Input Name   :$11. +1 City  :$31. / @1 Salary:comma. +1 Subject  :$23.
run;
Mansi
Fluorite | Level 6

Hi Gautham,

 

Thanks you for your reply. Below is the sample observation lines from the file -

 

Terence      Mumbai      
$24,00.20       Spanish
Shruti       Bangalore
$22,00.50       German
Nivita       Indore
$25,00.00       Belgian

 

Inputs are -  Name$ 1-12 City$ 14-26  Salary 1-15 Language$ 17-24

I am not sure how to put salary since it has got Comma and dollar both.

 

 

gauthamk28
Obsidian | Level 7
did u try dollar9.2
Mansi
Fluorite | Level 6
Yes, just tried after you said. It did work. Thank you 🙂 So I have a question, if we are using dollar then don't we need to use the comma informat anymore?
Tom
Super User Tom
Super User

Sounds like your data is in fixed column locations.  To use an INFORMAT with fixed column data you need to specify the width in the INFORMAT value rather than using column ranges.

input
   Name $ 1-11 City $ 13-31 
 / @1 Salary comma15. Subject $ 17-23
;

Note that to read numeric data that contains both $ and commas you can just use the COMMA informat. It will strip out the $ and the commas and then read the result like a normal number.  Also do NOT add a decimal part to the INFORMAT unless your source data has deliberately not included the period and you want to tell SAS where to assume the period should be.  If you read '1234' using 4.2 informat it will read it as 12.34 instead of 1,234.

 

If you want to display the result using the $ then you need to attach the DOLLAR format to the variable using a FORMAT statement.

 

 

Mansi
Fluorite | Level 6
Hi Tom,

Thank you so much for your detailed response. This is exactly what I wanted to know. In my statement I was confused how to apply both, Comma and dollar to a variable. Now this makes my concept clear.

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
  • 6 replies
  • 1445 views
  • 1 like
  • 3 in conversation