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

Hello Experts,

 

I have the file (herewith attached), I don't know the number of variables in it, so I can't procced with 

infile\informat\format and input. I'm wondering if there is another way to import the txt. I know that proc import doesn't work with txt. 

 

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Doesn't look "structured" to me. It just seems to be a list of filenames.

data want;
  infile 'c:\downloads\Liste.txt' dlm='[,]' recfm=n;
  input file :$200. @@;
  file=dequote(file);
run;

View solution in original post

11 REPLIES 11
Tom
Super User Tom
Super User

Doesn't look "structured" to me. It just seems to be a list of filenames.

data want;
  infile 'c:\downloads\Liste.txt' dlm='[,]' recfm=n;
  input file :$200. @@;
  file=dequote(file);
run;
SASdevAnneMarie
Barite | Level 11
Thank you, Tom ! That works.
What means the ":" before $200. ?
Tom
Super User Tom
Super User

The colon modifier on the input statement let's you include an in-line informat in the INPUT statement without actually switching from using LIST mode input (read the next "word" in the line) to FORMATTED mode input (read EXACTLY the number of characters I tell you to read). 

 

This allowed me to skip defining the length of the FILE variable since SAS will assume since I am using the character informat with a width of 200 that the variable should be character with a length of 200.

data want;
  infile 'c:\downloads\Liste.txt' dlm='[,]' recfm=n;
  length file $200 ;
  input file @@;
  file=dequote(file);
run;
SASdevAnneMarie
Barite | Level 11
Thank you, Tom !
SASdevAnneMarie
Barite | Level 11
Tom, last question: what means @@ after "file" ? Thank you !
Tom
Super User Tom
Super User

On an INPUT statement the trailing @ has an impact on how the line and column pointer moves.

The "double trailing at" means to keep the pointer exactly where it is even when starting another iteration of the data step.  So you can read multiple observations from the the same line of input text.

The "single trailing at" also means to keep the pointer where it is, but only for any other input statements in this same iteration of the data step.  The next iteration will start at the beginning of the next line of input text.

SASdevAnneMarie
Barite | Level 11
Thank you very much, Tom !
SASdevAnneMarie
Barite | Level 11
Hello Tom,
When I run the program with @@ I have the same results as with one @. Could you explain please 🙂

Thank you !
Marie
Tom
Super User Tom
Super User

@SASdevAnneMarie wrote:
Hello Tom,
When I run the program with @@ I have the same results as with one @. Could you explain please 🙂

Thank you !
Marie

That is because of the RECFM=N.  SAS is not treating the input as lines of text, just a stream of data.  Try the single and double at without the RECFM=N on the INFILE statement and see if you get different behavior.

 

SASdevAnneMarie
Barite | Level 11
Thank you, Tom !
ballardw
Super User

Your "text" file doesn't have any end of line markers which adds a bit of complication. It also appears to have exactly one variable.

 

 

I think this works :

data junk;
  infile "<path>\liste.txt" dlm='[],' recfm=n ;
  informat a $35.;
  input a @@;
run;

The RECFM option treats the input file as a single stream. Because your data starts with a [ and ends with ] I include them as delimiters along with the comma.

INPUT a @@ basically means "keep reading repeatedly".

 

I made a guess as to the variable length. Sue me if it is wrong. You may want to remove the quotes around the values.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1258 views
  • 6 likes
  • 3 in conversation