data DTT;
infile "/home/coccus030/sasuser.v94/DTS.txt" firstobs=2 truncover;
input model $1-12 Complaints 13-17;
run;
output result from my SAS query
Center Complaints
Raading 27. 84
Teledo (BMT) 23.29
Acchmond 21. 93
Mewport Mews 20.53
Moofolk 19.57
Data should look
Center Complaints
Raading 27.84
Teledo (BMT) 23.29
Acchmond 21. 93
Mewport Mews 20.53
Moofolk 19.57
I tried to upload directly from SAS on demand but fail if anyone can provide the way. thank you so much
Your data is tab delimited. Since tabs can vary depending on the system (4 or 6 spaces usually) you can get different appearances.
But specifying a tab as a delimiter allows me to read it correctly.
data DTT; infile "C:\Users\fareeza.khurshed\Downloads\DTT.txt" dlm='09'x firstobs=2 truncover; informat model $12.; input model $ Complaints ; run;
input model $1-12 Complaints 13-17;
The above reads the first variable as the characters from positions 1-12, and complaints from 13-17. If 27. is read in in the first instance, then that is because it is within position 1-12. As we cannot see the file you have its hard to say, is is perhaps delimited? Why use the positional 1-12 if so?
If I don't use 1-12, it won't read at all.
Please see attached original text file
Can you show what your text file looks like exactly?
Ideally upload a small sample.
@elsalam wrote:
data DTT;
infile "/home/coccus030/sasuser.v94/DTS.txt" firstobs=2 truncover;
input model $1-12 Complaints 13-17;
run;
output result from my SAS query
Center Complaints
Raading 27. 84
Teledo (BMT) 23.29
Acchmond 21. 93
Mewport Mews 20.53
Moofolk 19.57
Data should look
Center Complaints
Raading 27.84
Teledo (BMT) 23.29
Acchmond 21. 93
Mewport Mews 20.53
Moofolk 19.57
I tried to upload directly from SAS on demand but fail if anyone can provide the way. thank you so much
Since your data just doesn't line up, you will need to do a little programming to separate out the pieces. For example:
data DTT;
infile "/home/coccus030/sasuser.v94/DTS.txt" firstobs=2 truncover;
input @;
length model $ 12;
Complaints = input(scan(_infile_,-1), 6.);
model = substr(_infile_, 1, length(_infile_) - length(scan(_infile_,-1)));
run;
I think I got it right, but can't test it right now. See if it does what you need.
Your data is tab delimited. Since tabs can vary depending on the system (4 or 6 spaces usually) you can get different appearances.
But specifying a tab as a delimiter allows me to read it correctly.
data DTT; infile "C:\Users\fareeza.khurshed\Downloads\DTT.txt" dlm='09'x firstobs=2 truncover; informat model $12.; input model $ Complaints ; run;
Thank you Reeza
Informat model $12.
what does it do to the data?
I understand informat mean the data has some other character.
I tried to use & $12. but it did not work. Just wanted to understand if you can.
Thx
It specifies what format the input will be in, in this case it's looking for a (max) 12 character string.
@elsalam wrote:
Thank you Reeza
Informat model $12.
what does it do to the data?
I understand informat mean the data has some other character.
I tried to use & $12. but it did not work. Just wanted to understand if you can.
Thx
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.