From: Richard A. DeVenezia on 26 Jul 2010 15:44 On Jul 26, 5:27 am, m1st <lex.alt...(a)gmail.com> wrote: > Hello! > > I'm trying to generate unique string identifier using md5() function > from macro %sysfunc like: > %let __hash = %nrbquote(%sysfunc(md5(%sysfunc(rand(UNIFORM))))); Within the context of a single SAS session, you can also use MONOTONIC to get a unique identifier Monotonic never resets when called from the context of the macro environment . %let id = _%sysfunc(MONOTONIC()); When monotonic is used in the context of DATA Step or Proc SQL it resets at the step boundary and sequence count is maintained per invocation. -- Richard A. DeVenezia http://www.devenezia.com
From: m1st on 27 Jul 2010 02:22 On Jul 26, 5:24 pm, Patrick <patrick.mat...(a)gmx.ch> wrote: > "Certainly, I can generate identifiers with data step, but as SAS > does > not allow to include one datastep into another, this would be an ugly > solution. " > > So what do you need this MD5 values for. What do you want to achieve? > What do you have and what do you need? I need a macro which substitutes its call by some unique identifier, so that: data qwqwqw; id = "%genRandomId(8)"; run; becomes something like data qwqwqw; id = "A64F01D3"; run; See why it's better to avoid using datasteps for ID generation?
From: 760105 on 27 Jul 2010 02:27 http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work
From: m1st on 27 Jul 2010 02:27 On Jul 26, 6:49 pm, "data _null_;" <datan...(a)gmail.com> wrote: > On Jul 26, 7:56 am, m1st <lex.alt...(a)gmail.com> wrote: > > > > > On Jul 26, 3:43 pm, "Richard A. DeVenezia" <rdevene...(a)gmail.com> > > wrote: > > > > On Jul 26, 5:27 am, m1st <lex.alt...(a)gmail.com> wrote: > > > > > Hello! > > > > > I'm trying to generate unique string identifier using md5() function > > > > from macro %sysfunc like: > > > > %let __hash = %nrbquote(%sysfunc(md5(%sysfunc(rand(UNIFORM))))); > > > > > It takes md5 hash from a textual representation of a uniformly > > > > distributed random number. However, I've encountered some problems > > > > when quoting the output of md5. %nrbquote-ing is still unable to catch > > > > all the special characters appearing in md5 output. > > > > > The questions are: > > > > 1) How can I implement proper quoting in my case? > > > > 2) Or, if you have suggestions on implementing the same thing without > > > > md5, please share your mind. > > > > Try %QSYSFUNC > > > > -- > > > Richard A. DeVeneziahttp://www.devenezia.com > > > Actually, I tried it. No effect (more accurate, the same effect as the > > mentioned %let). > > It seems like SAS acquires macro quoting by mapping ASCII-codes of > > special characters like % or & to some non-printable ASCII subset. The > > fact is that MD5 returns a bit field, which is represented by 16 > > characters, not always printable, and sometimes they seem to collide > > with SAS special quoting values. > > Certainly, I can generate identifiers with data step, but as SAS does > > not allow to include one datastep into another, this would be an ugly > > solution.- Hide quoted text - > > > - Show quoted text - > > If you format the string could you still use it? > > 13 %let __hash = %qsysfunc(md5(%sysfunc(rand(UNIFORM))),hex16); > 14 > 15 %put &__hash; > 95C9FCF9CB0E4579 WOW! I missed this way of result formatting. datanull, thanks a lot! The solution works like a charm!
First
|
Prev
|
Pages: 1 2 Prev: Macro PROC SQL for QTD and YTD Next: How to import a .xlsx file over 256 columns? |