Hi
I am trying to change date in all the data sets and saving it on another location
This is what i have written so far
%macro datea(data_set,oldst );
data &data_set;
set &oldst;
new_date=input(old_DATE,date9.);
format new_date date9.;
run;
%mend datea;
%datea(&var1, &var2 );
** I need to change in such a way that I just give library name here it takes all the data set and copies to the second location with the same name
%let var1 = %str(abc.dddasas);
%let var2 = %str(cdf.dddasas);
A simpler method would be to use the already existing metadata which SAS provides in the form of the SASHELP.VTABLE (and VCOLUMN):
%macro mCopy (InLib=,OutLib=);
data _null_;
set sashelp.vtable (where=(libname=upcase("&InLib.") and memtype="DATA"));
call execute('data &outlib..'||strip(memname)||'; set &inlib..'||strip(memname)||'; new_date=today(); format new_date date9.; run;');
run;
%mend mCopy;
%mCopy (InLib=sashelp,OutLib=Work);
dates are integers.
formats are look-up tables for those integers.
you do not need to create a new variable in order to change the format
i.e. the way the date is displayed.
Here is the reference book to have
Thank you sir,
Essentially did not mean date date. It could have been a function calculation etc However i wanted to get all the data sets from one library to another library after doing the same calculations on the data sets from the source library and saving it to the destination library
Thank you for your time into looking through my macro
Thanks
It should not be date as such i would like to do essentially same calculations on my source library data sets and save it to another destination.
Thanks for looking through the code and your time
Here are a few questions that might cover what you are asking.
How do I get a list of all data set names within a folder?
How do I get a list of all data sets containing OLD_DATE within a folder?
How do I apply my macro for every data set name on a list?
How do I modify my macro to copy a data set from one folder to another?
Narrow down the question a little, and you are sure to get answers.
Hi Rahul
If the following is your qurey then find the code followed by the query.
You have some datasets in one location and all the datasets have a date variable(Old_Date with a particular date format).
Now you want to convert the date variable into date9. format and you want to save the dataset with the same name in another location.
filename Source "Source Path";
libname Source "Source Path";
libname Dest "Destination Path";
%macro dates(Dsn);
data Dest.&Dsn;
set Source.&Dsn;
new_date=input(old_DATE,dateformat);
format new_date date9.;
run;
%mend;
*Open the directory and find the number of items in the directory;
data _null_;
did=dopen("source");
dcnt=dnum(did);
call symput("Count",dcnt);
run;
%Macro datasets;
data datasets;
did = dopen("Source");
%do i = 1 %to &Count;
if scan(dread(did,&i),2,'.') eq "sas7bdat" then do; *Checking whether the filename read by dread() is SAS dataset or not;
Dsn = scan(dread(did,&i),1,'.'); * Reading the datasetname without extension;
call execute('%dates('||strip(Dsn)||')');
end;
%end;
run;
%mend;
%datasets;
Why not use Proc Copy? You would just need to assign two libnames and use select or exclude statements to copy the SAS datasets you want.
hi
the problem with proc copy is that i don't want to change anything within my code
also I would have to perform some calculations on source data set and save it to destination library. Which will also require me to keep drop variables, concatenate a few and likewise .
All i am trying to do is create a mac file which the user has to give source and destination library and the user should be done with it
The code i have written actually works however the user has to change data set name every time which i don't want to do.
Thanks
I have tried it using proc copy too it does work
thank you
Hi...
He wants to execute some statements while moving the datasets from one directory to other.
Using proc copy we cannot execute statements other than select and exclude.
A simpler method would be to use the already existing metadata which SAS provides in the form of the SASHELP.VTABLE (and VCOLUMN):
%macro mCopy (InLib=,OutLib=);
data _null_;
set sashelp.vtable (where=(libname=upcase("&InLib.") and memtype="DATA"));
call execute('data &outlib..'||strip(memname)||'; set &inlib..'||strip(memname)||'; new_date=today(); format new_date date9.; run;');
run;
%mend mCopy;
%mCopy (InLib=sashelp,OutLib=Work);
Thank You
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.