BookmarkSubscribeRSS Feed
arpit
Calcite | Level 5
I have 10 file having name

a1_03/03/2011.csv
a2_04/03/2011.csv
a3_05/03/2011.csv
a4_06/03/2011.csv
a5_07/03/2011.csv
a6_08/03/2011.csv
a7_09/03/2011.csv
a8_10/03/2011.csv
a9_11/03/2011.csv
a10_12/03/2011.csv

Each file contain 3column and 1 observation that is filename starttime endtime

I want to create a single dataset from above mention file records.

I am unable to write macro

Kindly help me .

Thanks in advance
4 REPLIES 4
data_null__
Jade | Level 19
You don't need a macro you need a data step to read from a FILEREF of concatenated files.

[pre]
Example 1: Referencing External Files
You can reference external files from a concatenated list of files or directories.
The wildcard character * can be used in the FILENAME statement:

filename read ('c:\myfiles\a*.csv');
data new;
infile read;
input;
run;
[/pre]
arpit
Calcite | Level 5
Dear Data_null_,
Thanks for your kind information.
I want to write a macro Please help me

Regards,
Arpit
Ksharp
Super User
Hi.
The last thing you need to do is to concatenate these datasets vertically.
I do not code it , you can do it by yourself. The following is the code i wrote before.
[pre]





[/pre]



%let subdir=D😕sasdata\a\b\;



filename dir pipe "dir

&subdir.*.csv /B"
;



data new;



 infile dir truncover end=last;



 input filename  $100.;



 filename=cats("&subdir",filename);



 call symputx(cats('path',_n_),filename);



 call symputx(cats('dsn',_n_),scan(scan(filename,5,'\'),1,'.'));



 if last then call symputx('nobs',_n_);



run;



%put _user_;



 



%macro import;



%do i=1 %to &nobs;



 



data WORK.&&dsn&i;                                      
;



      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */



      infile "&&path&i" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;



        
informat VAR1
best32. ;



        
informat VAR2
$30. ;



        
informat VAR3
comma30. ;



        
informat VAR4
comma30.;



        
informat VAR5
comma30.;



        
informat VAR6
comma30.;



        
informat VAR7
comma30.;



        
informat VAR8
comma30.;



        

informat VAR9
best12.;



        
format VAR1
best12. ;



        

format VAR2
$30. ;



        
format VAR3
best32.2 ;



        
format VAR4
best32.2;



        
format VAR5
best32.2;



        

format VAR6
best32.2;



        
format VAR7
best32.2;



        
format VAR8
best32.2;



        
format VAR9
best12. ;



      input



                 
VAR1



                 
VAR2



                 
VAR3



                 
VAR4



                 
VAR5



                 
VAR6



                 
VAR7



                 
VAR8



                 
VAR9



      ;



 



                 
;



      if _ERROR_ then call symputx('_EFIERR_',1); 

/* set ERROR detection macro
variable */



      run;



%end;



%mend import;



 



%import




[pre]





[/pre]



Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 905 views
  • 0 likes
  • 4 in conversation