BookmarkSubscribeRSS Feed
sasbegginer
Calcite | Level 5
Hi i am using sas and need help on construction a new URN. I currently have a URN field which is populated with 1_1urn, 1_2urn, 1_3urn etc..now everytime the code is run i need the urn to increment by 1..so the next time it is run the urn is 2_1urn, 2_2urn, 2_3urn and if run again 3_1urn, 3_2urn etc..any ideas..i am having trouble storing the incremented value. At the moment iv got

urn = 1
urn = urn + 1

everytime this is run it read the 1 i need a way to store the new urn value and so it doesnt read the 1...Do i need to create another table?? Also is there a easier way of doing this in DI studio?
9 REPLIES 9
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You could create a permanent table; read it and update with each execution and store back the new "incremented" value. You would need to consider possibly how to deal with reruns - not sure about your requirement?

Scott Barry
SBBWorks, Inc.
sasbegginer
Calcite | Level 5
Sorry i don't understand what you mean...I have data which i get regular new loads and so i need to update the load number automatically from 1, 2, 3 etc. I then append this in to the URN. I just ned a way of updating 1 to 2 and then 2 to 3 everytime the code is submited
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Your idea of tracking a "current load number" across runs could be maintained as a permanent SAS dataset (you must create it in advance and prime it to start), which you process each time your program runs, as follows:

1) Using a DATA step, read the SAS file that has your variable to track the current "load number", and issue a CALL SYMPUT to assign a SAS macro variable with +1 from your "load number" variable.

2) Use the macro variable created in #1 above to update your database variable(s) as required.

3) When processing is finished, store back the new "current load number" into your permanent SAS dataset.


Scott Barry
SBBWorks, Inc.
sasbegginer
Calcite | Level 5
Ok so i have created a dataset which had a looks like this

ID
1

I have looked at the CALL SYMPUT in the help files and have tried to implement it but cant get it right...also how would i store the current load number back?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Please share what SAS code you have executing which doesn't provide the SYMPUT correctly, preferably in an executed SAS log (COPY/PASTE into a post-reply).

Also, for your own debugging, consider using the SAS command(s) below to display your user-assigned macro variables -- and there are considerations for GLOBAL versus LOCAL macro variables depending on whether or not you are using the SAS MACRO language:

%PUT _USER_;
...or...
%PUT _LOCAL_;
%PUT _GLOBAL_;

And for diagnosing your SAS program, you will want to activate as much SAS-generate compilation/processing output directed to your SAS log, using the command:

OPTIONS SOURCE SOURCE2 MACROGEN /* SYMBOLGEN */ MPRINT;


And, you would use the macro variable from the SYMPUT to assign the ID variable a new/replacement value in a DATA step, writing back to your permanent SAS data library member used for tracking.

Scott Barry
SBBWorks, Inc.

SAS Macro Language: Reference - Scope of Macro Variables:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm

SAS Macro Language: Reference - Introduction to the Macro Facility
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm

SAS Macro Programming for Beginners
Susan J. Slaughter, Avocet Solutions, Davis, CA
Lora D. Delwiche, Delwiche Consulting, Winters, CA
http://www2.sas.com/proceedings/sugi29/243-29.pdf
sasbegginer
Calcite | Level 5
Ok, i have now fixed sas code i have just been playing around with the SYMPUT function..being new to SAS i havent fully got my head around macros...
sasbegginer
Calcite | Level 5
Sorry i ment...
Ok, i have no fixed sas code i have just been playing around with the SYMPUT function..being new to SAS i havent fully got my head around macros...
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I would not recommend using macros if you don't have to. The macro variable discussion / documentation occurs within the SAS Macro Language discussion though.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
Very quick and dirty: But it may give you a starting point.

data urn;
u = 1;
output;
run;

data two;
do i = 3 to 7;
output;
end;
run;

data three urn(keep = u) ;
retain urn;
merge two(in = t) end = eof urn;
if _n_ = 1 then urn = u;
urn = urn + 1;

if t then output three;
if eof then do u = urn; output urn; end;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 1590 views
  • 0 likes
  • 3 in conversation