×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Renaming/Delete part of a label of a SAS variable in the dataset

Renaming/Delete part of a label of a SAS variable in the dataset

Renaming/Delete part of a label of a SAS variable in the dataset

(OP)
I got a dataset with variables RESULTS00-RESULTS36, each with a label with something like 'Result blabla'. Now I want to remove the 'Result' from the label so it will be 'blabla' alone.

%MACRO rem_res(ds);
DATA data2;
    SET &ds.;
   
    %DO i=0 %TO 36;
    res=TRANWRD(VLABEL(RESULTS0&i.),"Result","");
    put res;
    CALL SYMPUT('macr_res',res);    
    %PUT &macr_res.;
    LABEL RESULTS0&i. = &macr_res.;    
    %END;
RUN;
%MEND;

However, using this code it does not recognize the macr_res anymore. Also, it puts just &macr_res., what's wrong?

RE: Renaming/Delete part of a label of a SAS variable in the dataset

Hi,

You need to use PROC DATASETS in this case.
The syntax would be like;

PROC DATASETS lib = whaterver_lib;
modify whatever_dataset;
/* this part can be automated by creating macro variable */
label RESULTS00 = blabla;
.
.
.
label RESULTS36 = XXXXX;
/* ************************************ */
quit;

As commented above the label statements part can be automated by creating some macro variable; you can refer to code snippent below

data _null_;
set input_dataset_name;

lengh str $ 256;
%do i = 1 %to 36;
str = trim(left(str)) || "label "|| "result0&i = "||TRANWRD(VLABEL(RESULTS0&i.),"Result","") || ";";
%end;

call symput ('lbl_str', str);
run;

Now you can use this customized label statement in PROC DATASETS code as below;

     PROC DATASETS lib = whaterver_lib;
      modify whatever_dataset;
      &lbl_str;
     quit;


I hope this will work.
  

sasbuddy
http://sites.google.com/site/sasbuddy/
 

RE: Renaming/Delete part of a label of a SAS variable in the dataset

Hi specialn,

I analyzed your query more closely;
I found out that the function VLABEL() cant be used inside another fucntion. So operating it separately and then using that result in TRANWRD() function would most probably work.

You can refer the following code snippet.

********************************************************************

data temp;
input RESULTS00-RESULTS36;
cards;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
;
run;

%global lbl_str;

options symbolgen;
%macro assign_label;

data _null_;
length str $ 1500;
%do i=0 %to 36;
    %if &i lt 10 %then %do;
        str = trim(left(str)) || "LABEL RESULTS0&i = RESULTS 0&i;";
    %end;
    %else %do;
        str = trim(left(str)) || "LABEL RESULTS&i = RESULTS &i;";
    %end;
%end;
call symput('lbl_str', str);
run;

%mend assign_label;

%assign_label;

proc datasets lib=work;
modify temp;
&lbl_str;
quit;

proc contents data = work.temp;
run;


%macro modify_label;

data _null_;
set temp;
length str $ 1500;
%do i=0 %to 36;
    %if &i lt 10 %then %do;
        vlbl = trim(left(VLABEL(RESULTS0&i)));
        str = trim(left(str)) || "LABEL RESULTS0&i =" || trim(left(TRANWRD(vlbl,"RESULTS", ""))) || ";" ;
    %end;
    %else %do;
        vlbl = trim(left(VLABEL(RESULTS&i)));
        str = trim(left(str)) || "LABEL RESULTS&i =" || trim(left(TRANWRD(vlbl,"RESULTS", "")))|| ";" ;
    %end;
%end;
call symput('lbl_str', str);
run;

%mend modify_label;

%modify_label;

proc datasets lib=work;
modify temp;
&lbl_str;
quit;

proc contents data = work.temp;
run;

sasbuddy
http://sites.google.com/site/sasbuddy/
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close