Hello!
I'm attempting to use macro variables to track versioning in my programs. Ideally, the end product would be an output file with names and version dates for each of my programs.
I've added a global macro variable to each program that stores the version date. For example:
%LET Prog1_Vsn=%STR(2020.02.21);
I have a dataset with a column for the name of this macro variable, the full program name, and a description. For example:
MacroVar Name Desc
&Prog1_Vsn Program 1 First program in set
I would like SAS to create a new variable that resolves the macro variable listed in the dataset, like this:
MacroVar Name Desc Version
&Prog1_Vsn Program 1 First program in set 2020.02.21
Is this possible? Is there a better way to achieve this result? I'm using base SAS 9.4. Many thanks for any help!
PS- I do realize that I can hard-code this by using something like IF name = "Program 1" THEN Version = "&Prog1_Vsn". I would like a smarter solution, if at all possible.
Something like this?
data have;
infile cards dsd dlm='|' truncover ;
input MacroVar :$32. Name :$50. Desc :$200. ;
cards4;
Prog1_Vsn|Program 1|First program in set
;;;;
%let Prog1_Vsn=2020.02.21;
data want ;
set have;
length version $30;
version=symget(macrovar);
run;
proc print;
run;
Obs MacroVar Name Desc version 1 Prog1_Vsn Program 1 First program in set 2020.02.21
@vickerse333 - With all due respect you can build your own version control functionality, but in my experience using a version-control tool with SAS programs is a far better option and is not as complicated as you might think.
@vickerse333 - If you are using Enterprise Guide, then it works well with Git: https://documentation.sas.com/?docsetId=egug&docsetTarget=p078cl08fol7hkn11a8nf1f9izq7.htm&docsetVer...
I'd also advise finding out what version control tools are used in your organisation and trying those out.
Something like this?
data have;
infile cards dsd dlm='|' truncover ;
input MacroVar :$32. Name :$50. Desc :$200. ;
cards4;
Prog1_Vsn|Program 1|First program in set
;;;;
%let Prog1_Vsn=2020.02.21;
data want ;
set have;
length version $30;
version=symget(macrovar);
run;
proc print;
run;
Obs MacroVar Name Desc version 1 Prog1_Vsn Program 1 First program in set 2020.02.21
Symget didn't work. I get lots of error messages like this:
NOTE: Invalid argument to function SYMGET('&CM_Ann_Ref_'[12 of 19 characters shown]) at line 456
column 15.
Any other ideas?
@vickerse333 wrote:
Symget didn't work. I get lots of error messages like this:
NOTE: Invalid argument to function SYMGET('&CM_Ann_Ref_'[12 of 19 characters shown]) at line 456
column 15.
Any other ideas?
SYMGET wants the NAME of the macro variable. Why did you include the ampersand?
That appears to have been the issue. Thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.