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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?  

elsalam
Calcite | Level 5

If I don't use 1-12, it won't read at all.

 

Please see attached original text file

Reeza
Super User

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


 

Astounding
PROC Star

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.

Reeza
Super User

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;
elsalam
Calcite | Level 5

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

Reeza
Super User

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 985 views
  • 0 likes
  • 4 in conversation