BookmarkSubscribeRSS Feed
78282219
Calcite | Level 5

I currently have a macro which moves my dataset from one branch to another. In each movement, the date is updated. However, I am having trouble with removing the old date autonomously before inputting the new date, any advice?

 

The code is:

%Macro Merge_Branch(Branch = , Filename = , Library = );

	%Let Timestamp = %sysfunc(putn(%sysfunc(date()),yymmddn8.));

	%if &Branch. = Latest_Commit %then %do;
		
		Data LC._&Timestamp._&Filename.;
		set &Library..&Filename.;
		run;

	%end;

	%else %if &Branch. = Staging %then %do;

		%Let Filename = _20180909_Financial_Input;
		%Let Filename_temp = %scan(&Filename.,2,'_');
                %Let Date_String = %scan(&Filename.,1,'_');
                /* this is the section where I get stuck the dash is a subtraction i.e. I want to remove the date and just have the string*/
		%Let Filename_Stg = &Filename_temp - &Date_String;

		Data Stg._&Timestamp._&Filename_Stg.;
		set LC.&Filename.;
		run;

	%end;

%mend;

Input data can be made like this

data LC._20180909_Financial_Input;
var var1;
datalines;
1
1
1
1
;
run;

%Macro Merge_Branch(Branch = Staging , Filename = Financial_Input, Library = LC );

/*Note, in this macro the library is not important because it will always move from LC to STG*/
2 REPLIES 2
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

is the - a typo

%Let Filename_Stg = &Filename_temp - &Date_String;

should it be 

%Let Filename_Stg = &Filename_temp_&Date_String;

78282219
Calcite | Level 5

It's more like a subtraction so i'm trying to make the following happen

 

_20181009_Financial_Input - _20181009_ = Financial_Input

 

then in the next step I will create a dataset name where there will be the most recent date (in this case it is the most recent date but in future there will be discrepancies)

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 989 views
  • 0 likes
  • 2 in conversation