BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rahul88888
Obsidian | Level 7

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);

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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);

View solution in original post

11 REPLIES 11
Ron_MacroMaven
Lapis Lazuli | Level 10

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

The Essential Guide to SAS Dates and Times, Second Edition

rahul88888
Obsidian | Level 7

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

rahul88888
Obsidian | Level 7

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

Astounding
PROC Star

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.

MadhuKorni
Quartz | Level 8

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;

lgregg
Calcite | Level 5

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.

rahul88888
Obsidian | Level 7

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

rahul88888
Obsidian | Level 7

I have tried it using proc copy too it does work

Smiley Happy thank you

MadhuKorni
Quartz | Level 8

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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);

rahul88888
Obsidian | Level 7

Thank You Smiley Happy

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
  • 11 replies
  • 1338 views
  • 5 likes
  • 6 in conversation