use of !! in Call Symput in SAS

875 Views Asked by At

Could anyone tell me what this data step is doing? I have never seen the use of "!!" or a "double exclamation mark" before?

data _null_;
set &dset_in.;
if i = _n_ then do i=1 to nvar;
    call symput ("var" !! strip(put(_n_, 3.)), strip(Variabile));
    call symput ("min" !! strip(put(_n_, 3.)), strip(lim_inf));
    call symput ("max" !! strip(put(_n_, 3.)), strip(lim_sup));
end;
run;

A general gist of the loop would be helpful too, thanks

3

There are 3 best solutions below

0
On BEST ANSWER

It's just used for concatenation (instand of || ).

0
On

Answering the second part of the question, what it's doing is:

There is a variable i which has some value indicating a row that the user wants to retrieve values from. When that row is reached, the values in three variables are stored in macro variables that have the row number in their name, such as if i=5, then it will take the 5th row, and put the three variables in &var005, &min005, &max005.

However, there are a number of issues with this code. First off, reusing i in that loop is a bad idea; while it doesn't do anything permanent, it easily could with minor changes that could arise from other features/bugfixes.

Second, the loop as currently structured is pointless. It's not doing anything based on i, so it's just putting the same 3 values into the same 3 macro variables multiple times. It looks to me like this is someone's take on code they copied from the internet, but slightly misunderstood.

Probably what it should do, is something like this:

data _null_;
  set &dset_in.;
  call symput ("var" !! strip(put(_n_, 3.)), strip(Variabile));
  call symput ("min" !! strip(put(_n_, 3.)), strip(lim_inf));
  call symput ("max" !! strip(put(_n_, 3.)), strip(lim_sup));    
run;

That would make macro variables for each row with the row number in the name, using the automatic data step loop. This is just a guess, though, not knowing anything about the program beyond what I see here.

But that's all with the caveat that this whole operation is a bad idea; storing data values in macro variables is poor programming practice. Don't do it.

7
On

!! is a concatenation operator as per the documentation:

https://documentation.sas.com/?docsetId=lrcon&docsetVersion=9.4&docsetTarget=p00iah2thp63bmn1lt20esag14lh.htm&locale=en

The code is creating a set of macro variables VAR001, MIN001 MAX001 to store values in a data set. In general this is a bad practice, if you need to do this there's usually an easier way somehow.