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 !
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;
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;
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;
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 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.
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 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.