BookmarkSubscribeRSS Feed
Kally80
Calcite | Level 5

Hi All,

 

Im using a code that helps read the contents of a particular directory, as below:

 

%let filepath = "&sharedrive\Projects";

filename fref PIPE %sysfunc(quote(dir &filepath /AD /b)) lrecl=32767;

data tmp;

   infile fref truncover;

   input study $1000;

   dir="&sharedrive\Projects";

run;

 

On running the code, there is no error and I also get the correct number of records [there were 105 subfolders in Projects directory and the dataset TMP also had 105 records). But for some reason the STUDY variable is blank instead of having the names of the subfolders. [Please note that the "sharedrive" macro variable resolves correctly based on my setup.sas file that I call in the main program].

 

Thanks in advance.

Kally

3 REPLIES 3
LinusH
Tourmaline | Level 20

There are many ways to input data, one way to fix this is by using formatted input:

   input study $1000.;
Data never sleeps
Tom
Super User Tom
Super User

You a missing the period that would change the meaning of the INPUT statement.

What you ran:

input study $ 1000 ;

Which makes STUDY as a one byte character variable and populates it with the 1,000th  byte on the line.

What you wanted:

input study $1000. ;

Which will make STUDY as a 1,000 byte character variable and populate it with the left aligned value of the first 1,000 bytes from the line.

 

That is a very common typo.

 

Since you appear to want the whole line you could also just use the _INFILE_ automatic variable instead.

data tmp;
   infile fref truncover;
   length study $1000 ;
   input;
   study = _infile_;
   dir="&sharedrive\Projects";
run;

If you did need the leading spaces removed as your original code was doing you could use

study = left(_infile_) ;
Kally80
Calcite | Level 5

Hi Tom,

 

Thanks for your response. I too realized the issue quite late. Infact what I have done is that I introduced a length statement [like how you mentioned] and got the code working fine.

Thanks again for taking the time to get back.

 

Regards,

Kailly

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Update

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 312 views
  • 0 likes
  • 3 in conversation