DATA Step, Macro, Functions and more

Help with Informats

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Help with Informats

[ Edited ]

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.


Accepted Solutions
Solution
‎02-17-2017 01:43 AM
Super User
Super User
Posts: 7,079

Re: Help with Informats

[ Edited ]

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


All Replies
Contributor
Posts: 21

Re: Help with Informats

[ Edited ]

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;
New Contributor
Posts: 4

Re: Help with Informats

Posted in reply to gauthamk28

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.

 

 

Contributor
Posts: 21

Re: Help with Informats

did u try dollar9.2
New Contributor
Posts: 4

Re: Help with Informats

Posted in reply to gauthamk28
Yes, just tried after you said. It did work. Thank you Smiley Happy So I have a question, if we are using dollar then don't we need to use the comma informat anymore?
Solution
‎02-17-2017 01:43 AM
Super User
Super User
Posts: 7,079

Re: Help with Informats

[ Edited ]

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.

 

 

New Contributor
Posts: 4

Re: Help with Informats

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 184 views
  • 1 like
  • 3 in conversation