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
There are many ways to input data, one way to fix this is by using formatted input:
input study $1000.;
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_) ;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.