Help using Base SAS procedures

Assigning Labels --- HELP!

Reply
Regular Contributor
Posts: 155

Assigning Labels --- HELP!

Hi,

In my data set I have columns

C1 C2 C3 ------C20  C30----C41;

There are no columns with names from C21--- C29

I require to assign label to those columns

From c1 to c20

ATTRIB C1    LABEL='APP C1'

ATTRIB C2    LABEL='APP C2';

From C30 to C41

ATTRIB C30  LABEL ='DEN C30';

ATTRIB C31  LABEL='DEN  C31';

I tried to use array to do that but it is not working.

Any help will be appreciated.

Super User
Posts: 17,963

Re: Assigning Labels --- HELP!

There is no fast/easy way to do this, besides a macro or code gen.

If its a one time operation, I'll usually do it in Excel instead to get the statements I need.

Respected Advisor
Posts: 3,777

Re: Assigning Labels --- HELP!

You can create labels from data with PROC TRANSPOSE.  This example assumes that all C: variables are the same type and numeric.  If your situation is more complicated we can fix that, but you will need to describe what you actually have.

data have;
   array c
  • c1-c20 c30-c41;
      
  • retain c 9;
      
    run;
    proc transpose data=have(obs=0) out=vars;
       var c:;
       run;
    data vars;
       set vars;
       i = input(substrn(_name_,2),f8.);
       length _label_ $64;
      
    if i le 20
         
    then _label_ = 'APP';
         
    else _label_ = 'DEN';
       _label_ = catx(
    ' ',_label_,_name_);
       run;
    proc print;
      
    run;
    proc transpose data=frame out=labels(drop=_name_);
       run;
    proc contents varnum;
      
    run;
    data have;
       if 0 then set labels;
       set have;
       run;
    proc print label;
      
    run;
    PROC Star
    Posts: 7,366

    Re: Assigning Labels --- HELP!

    My suggested approach is similar to data_null_'s, but I like to use a data _null_ step as a code generator.  e..g.:

    /*create a data set for testing purposes*/

    data have;

      retain c1-c20 (20*1);

      retain c30-c41 (12*1);

      output;

    run;

    /*create an include file*/

    filename dolabels temp;

    data _null_;

      set have (obs=1);

      file dolabels;

      array APPDEN{*} c1-c20 c30-c41;

      length varname $32;

      put "label";

      do i=1 to dim(APPDEN);

        varname=vname(APPDEN(i));

        put varname @;

        if i lt 21 then put '="APP '@;

        else put '="DEN '@;

        put varname @;

        put '" ';

      end;

      put ';';

    run;

     

    /*Run the include file in a data step  */

    data want;

      array APPDEN{*} c1-c20 c30-c41;

      set have;

      %inc dolabels;

    run;

    Super User
    Super User
    Posts: 6,502

    Re: Assigning Labels --- HELP!

    For N this small it is easy to just type one label statement and replicate and make the changes by hand.

    Now if I still had access to WYLBUR editor (http://dl.acm.org/citation.cfm?id=362234) the CHANGE command to do the modifications for you in a one line command, but I haven't used MVS in 25 years and I doubt anyone who is still uses WYLBUR.

    Ask a Question
    Discussion stats
    • 4 replies
    • 252 views
    • 0 likes
    • 5 in conversation