BookmarkSubscribeRSS Feed
JasonNC
Quartz | Level 8

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.

4 REPLIES 4
Reeza
Super User

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.

data_null__
Jade | Level 19

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;
    art297
    Opal | Level 21

    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;

    Tom
    Super User Tom
    Super User

    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.

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 4 replies
    • 844 views
    • 0 likes
    • 5 in conversation