02-07-2017 03:28 PM
I have a bunch of raw datasets, but for one subject, it has two IDs.
I want to change the wrong ID to the correct one, and generate another set of raw data.
Is there an efficient way to do this change without running it many times for each dataset?
if ID="A0001" then ID='B0001";
02-07-2017 04:09 PM
Do you have a dataset with the wrong ID's?
How many datasets and do they have a naming convention?
@fengyuwuzu You've posted enough to know to post sample data, so can I assume you're only asking for methodological help here?
You can create a format and apply it to all your datasets so that it 'shows' as correct or manually loop through and reassign. You can't reassign using a proc datasets so that means recreating your data. If you use a format, you can apply it using proc datasets and not recreate all your datasets. Depending on the size of datasets this may be a factor in the solution you choose.
It seems easier to create a format and use as you go as well, especially if changes occur over time.
02-07-2017 04:19 PM
Assuming you have a file that contains a list of those files, here is one way to do it:
libname raw 'c:\art\test'; libname newlib 'c:\art\out'; /*proc sql noprint;*/ /* select file into: files separated by '*'*/ /* from dictionary.tables*/ /* where libname='RAW'*/ /* ;*/ /*quit;*/ data filelist; informat file $32.; input file; cards; test1 test2 test3 ; proc sql noprint; select file into: files separated by '*' from work.filelist ; quit; %macro doit; %let i=1; %do %while (%scan(&files.,&i.,*) ne ); data newlib.%scan(&files.,&i.,*); set raw.%scan(&files.,&i.); if ID="A0001" then ID="B0001"; run; %let i=%eval(&i.+1); %end; %mend doit; %doit
Note that I commented out the section that would have accomplished the task for all of the files in the raw directory.
Art, CEO, AnalystFinder.com