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

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

@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
Fluorite | Level 6
Can you point me in the direction of some materials on this subject?
SASKiwi
PROC Star

@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.

Tom
Super User Tom
Super User

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
Fluorite | Level 6

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?

Tom
Super User Tom
Super User

@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?

vickerse333
Fluorite | Level 6

That appears to have been the issue. Thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 799 views
  • 0 likes
  • 3 in conversation