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.
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.
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;
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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.