Hello SAS Experts,
Is there a way to read the file name acutally processed and put it in the first column of the dataset?
data Import_Import;
infile datalines;
length fil2read $40;
input fil2read $;
infile dummy filevar=fil2read end=done DSD
DLM=';';
do while(not done);
INPUT
A : $CHAR11.
B : $CHAR11.
C : $CHAR11.
D : $CHAR100.
E : $CHAR96.
F : $CHAR1.
G : $CHAR6.
H : $CHAR2.
I : ?? COMMAX4.
J : $CHAR11.
K : $CHAR2.
L : ?? YYMMDD10.
M : $CHAR17.
N : $CHAR4.
O : $CHAR1.
P : $CHAR4.
Q : $CHAR1.
R : $CHAR1.
S : $CHAR4.
T : $CHAR1.
U : $CHAR1.
V : $CHAR1.
W : $CHAR1.
X : $CHAR4.
Y : $CHAR1.
Z : $CHAR1. ;
output;
end;
datalines;
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\B20154.csv'
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\N20154.csv'
;
Use the FILENAME option in the infile statement. You should also make sure it's long enough to hold the path.
length filename $256.;
infile dummy filevar=fil2read filename=filename end=done DSD
DLM=';';
source=filename;
This post may be of interest to you, especially if you have header rows in your files.
You were almost there. Since the FILEVAR is a temporary variable you need to assign it to a datastep variable.
data Import_Import;
length ReadFile $ 40.;
infile datalines;
length fil2read $40;
input fil2read $;
infile dummy filevar=fil2read end=done DSD
DLM=';';
ReadFile = Fil2read;
do while ..
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.