Hi
My code is below :
data new;
infile "F:\Raw.txt";
input Id Name $ +7 Incentive : percent. Salary $ 6-12;
run;
how should i remove comma in salary. Can we use commaW. in the above code if yes then how ?. Kindly help. I am attaching the raw data file.
data new;
infile cards missover;
input Id @3 Name $3. @14 Incentive :percent3. @7 salary :comma6. ;
cards;
1 Ram 25,000 40%
2 XYZ 31,000 25%
3 ABC 42,000 46%
4 MMN 52,000 20%
;
run;
My code is below
data new;
infile "F:\Raw.txt";
input Id Name $ +7 Incentive : percent. Salary $ 6-12;
run;
i have attached my raw file. I want to know how should i remove comma from salary. I have considered incentive after name and want to mention salary after incentive. Although in the raw data the sequence is different.
You cannot use column input to read nonstandard data such numbers that has comma. You would need a formatted input like:
input @(column position) Salary comma6.; /*Column position is the column pointer to which the input pointer should be instructed to move in the input buffer and start reading values from that point.*/
HTH,
Naveen Srinivasan
Hi Naveen,
In the raw data below
1 Ram 25,000 40%
2 XYZ 31,000 25%
3 ABC 42,000 46%
4 MMN 52,000 20%
I want to get table like below
First column: ID
Second Column: Name
Third Column: Incentive although it is the fourth column in Raw data
Fourth Column: Salary, although it is the third column in Raw data that also without comma.
How to do it ?
@manish_1 wrote:
Hi Naveen,
In the raw data below
1 Ram 25,000 40%
2 XYZ 31,000 25%
3 ABC 42,000 46%
4 MMN 52,000 20%
I want to get table like below
First column: ID
Second Column: Name
Third Column: Incentive although it is the fourth column in Raw data
Fourth Column: Salary, although it is the third column in Raw data that also without comma.
How to do it ?
Before the input statement, add a format or length statement with the variables in the desired order (the format statement does not need to contain formats).
This is good example of why you should always define your table structure and variables instead of letting SAS guess at what definition you intended based when you first reference the variable. Use the LENGTH or ATTRIB statement to define the variables. You can also assign INFORMAT to make the INPUT statement easier.
So in this case define the variables in the order you want and then on the INPUT statement read them in the order they appear in the raw data.
data want;
length id 8 name $20 incentive salary 8 ;
informat incentive percent. salary comma. ;
input id name salary incentive;
cards;
1 Ram 25,000 40%
2 XYZ 31,000 25%
3 ABC 42,000 46%
4 MMN 52,000 20%
;
Please try the comma.
data new;
infile cards missover;
input Id Name $3. Incentive :comma6. ;
cards;
1 Ram 25,000
2 xyz 31,000
3 Abc 42,000
4 MMN 52,000
;
run;
data new;
infile cards missover;
input Id @3 Name $3. @14 Incentive :percent3. @7 salary :comma6. ;
cards;
1 Ram 25,000 40%
2 XYZ 31,000 25%
3 ABC 42,000 46%
4 MMN 52,000 20%
;
run;
Thanks
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!
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.
Ready to level-up your skills? Choose your own adventure.