Automagically Opening Dataset and Copying Variable Value

I attended PharmaSUG China 2016 in Beijing last month, along with my line manager. There were a large number presentations this year. One presentation made a deep impression on me. The presenter shared some useful tips on presentation, such as automagically opening dataset and copying variable value. The source code is not available, so I created three small macros to accomplish these common tasks.

  1. %markdsn, automagically opens the dataset selected.
    %macro markdsn();
    gsubmit "
    dm 'wcopy';

    filename clip clipbrd;

    data _null_;
    infile clip;
    input;
    call execute('dm ""vt '||_INFILE_||';"" continue ;');
    run;

    filename clip clear;";
    %mend markdsn;
  2. %markcode, runs the selected code and automagically opens the last created dataset
    %macro markcode();
    gsubmit "
    dm 'wcopy';

    filename clip clipbrd;

    data _null_;
    infile clip end=eof;
    input;
    call execute(_INFILE_);
    if eof then call execute('%nrstr(dm ''vt &syslast;'' continue ;)');
    run;

    filename clip clear;";
    %mend markcode;
  3. %vvalue, automagically copies variable value.
    %macro vvalue();
    gsubmit '
    dm "wcopy";
    
    filename clip clipbrd;
    
    data _null_;
        infile clip;
        input;
        call symputx("var", _INFILE_);
    run;
    
    filename clip clear;
    
    proc sql noprint;
        select distinct &var into :varlst separated by "@"
        from &syslast
        ;
    quit;
    
    data _null_;
        if not symexist("increment") then call symputx("increment", 1, "g");
        else call symputx("increment", 1 + input(symget("increment"), best.), "g"); 
    run;
    
    filename clip clipbrd;
    
    data _null_;
        file clip;
        length value $32767;
        if &increment <= countw("&varlst", "@") then value=scan("&varlst", &increment, "@");
        else value=scan("&varlst", countw("&varlst", "@"), "@");
        put value;
    run;
    
    filename clip clear;';
    %mend vvalue;

Prerequisites:

  1. Store the macros in an autocall library
  2. In command line type below commands to assign keys to evoke these macros
    keydef 'F9' '%markdsn'
    keydef 'F10' '%markcode' 
    keydef 'F11' '%vvalue'

Usage:

  1. Select dataset name and then press F9
  2. Mark some code and then press F10
  3. Select variable name and then press F11, repeat the above process until getting the desired value
Xianhua Zeng /
Published under (CC) BY-NC-SA in categories Code  tagged with DM  GSUBMIT  PharmaSUG  PharmaSUG China 2016 

Previous Splitting Data Set Based on a Variable
Next Removing Duplicate Texts in a String