11-06-2013 11:11 AM
Hi All, I am new to SAS and am stuck at a point and would appreciate help.
I need to import 20 files(path and name stored in a dataset), change the values in a particular column and then export them each with a specified name.I am not able to do this. Please help me out here.
11-06-2013 01:07 PM
How do you identify the fields and values that need to be changed? If you summpy example data you will getter feeback but the basics are this.
create new ouput file name from file name in driver.
infile dummy1 csv filevar=file-name-variable-from-driver end=eof;
file dummy2 csv filevar=new-file-name;
do while(not eof);
11-06-2013 10:55 PM
I created a dataset with a single column(to_be_imported) which contains the path of those 20 .csv to be imported.
Now, I am stuck at this step:
for(i=1 to 20)
1. Import ith csv into a dataset say work. Edit a column. Export it back with the name xyz||i.csv into a specified folder.
11-07-2013 09:16 AM
Thanks for being patient. I succeeded with the part of importing them all one by one but I have a new trouble now. In the highlighted step, VAR2 column is getting
replaced but its truncated. Eg: If value_after_editing = HANDWASH, only HANDWA is coming in VAR2 column. It is truncating after 6/7 chars. I tried INFORMAT but then column becomes empty. Help please!
%MACRO edit_file(dataset, value_after_editing);
VAR2= "& value_after_editing";
/* First obtain the number of */
/* records in DATALOG */
IF 0 THEN SET &SCANFILE NOBS=X;
/* loop from one to number of */
/* records */
%DO I=1 %TO &RECCOUNT;
/* Advance to the Ith record */
SET &SCANFILE (FIRSTOBS=&I);
/* store the variables */
/* of interest in */
/* macro variables */
/* now perform the tasks that */
/* wish repeated for each */
/* observation */
/* Call SCANLOOP */
11-07-2013 11:00 AM
The truncation in your example likely means the the original dataset when created is creating var2 with a length of $ 6. You may need to consider how you are creating the datasets to ensure your variables are long enough to contain the desired change values.