BookmarkSubscribeRSS Feed
12 REPLIES 12
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Some tips on asking a question.  Whilst providing a descriptive title is great, providing some text in the post should also be done.   Provide example test data, in the form of a dataset, what you have tried, and what the output should look like.  At a guess:

data a;
  a=1;
  b=2;
  label a="abcd";
  label b="ADer";
run;

data _null_;
  set sashelp.vcolumn (where=(libname="WORK" and memname="A")) end=last;
  if _n_=1 then call execute('proc datasets library=work noprint; modify a;');
  call execute (cat(' attrib ',strip(name),' label="',strip(upcase(label)),'";'));
  if last then call execute('run; quit;');
run;

SrikanthY
Calcite | Level 5
I wanted to change only variable names that to for multiple data sets.

I have changed it for my convenience, but its displaying warning messages
on log. below is my code.


data _null_;
set sashelp.vcolumn (where=(libname="WORK" and memname in ("ADOMSG"
"AIR"))) end=last;
if _n_=1 then call execute(catx(" ",'proc datasets library=work nolist;
modify',memname,';'));
call execute (cat(' attrib ','name="',strip(lowcase(name)),'"
label="',strip(upcase(label)),'";'));;
if last then call execute('run; quit;');
run;

[image: Inline image 1]

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then you need to break up the code into by groups, this is why posting test data/required output is helpful, we don't have to guess:

data a;
  a=1;
  b=2;
  label a="abcd";
  label b="ADer";
run;
data b;
  a=1;
  b=2;
  label a="abcd";
  label b="ADer";
run;

data _null_;
  set sashelp.vcolumn (where=(libname="WORK" and memname in ("A","B")));
  by memname;
  if first.memname then call execute(cat('proc datasets library=work noprint; modify ',strip(memname),';'));
  call execute (cat(' attrib ',strip(name),' label="',strip(upcase(label)),'";'));
  if last.memname then call execute('run; quit;');
run;

Reeza
Super User

@SrikanthY wrote:
I wanted to change only variable names that to for multiple data sets.

I have changed it for my convenience, but its displaying warning messages
on log. below is my code.


data _null_;
set sashelp.vcolumn (where=(libname="WORK" and memname in ("ADOMSG"
"AIR"))) end=last;
if _n_=1 then call execute(catx(" ",'proc datasets library=work nolist;
modify',memname,';'));
call execute (cat(' attrib ','name="',strip(lowcase(name)),'"
label="',strip(upcase(label)),'";'));;
if last then call execute('run; quit;');
run;

[image: Inline image 1]

##- Please type your reply above this line. Simple formatting, no
attachments. -##

That first line should have been in your first post. 

Images aren't attached when responding via email as noted - simple formatting, no attachments. You need to specifically upload your images to the forum. 

Reeza
Super User

Is this just for presentation purposes? SAS isn't case sensitive when referring to variable names. 

LinusH
Tourmaline | Level 20

I think the issue somehow is valid.

You could have decided for a specific notation, that includes casing - usually for better "readability".

I don't have SAS at my fingertips right now, but I recall that I've tried to change the case of a variable/data set name, but if all the letter where the same, it didn't take effect. Or...?

Data never sleeps
data_null__
Jade | Level 19

@LinusH wrote:

I think the issue somehow is valid.

You could have decided for a specific notation, that includes casing - usually for better "readability".

I don't have SAS at my fingertips right now, but I recall that I've tried to change the case of a variable/data set name, but if all the letter where the same, it didn't take effect. Or...?


It works with PROC DATASETS or the RENAME data set option but not the RENAME statement.

 

data class;
   set sashelp.class;*(rename=(Name=NaMe));
   rename name=NaMe;
   run;
proc print;
   run;
proc datasets lib=work;
   modify class;
   rename Name=name;
   run;
proc print;
   run;
Ksharp
Super User

data a;
  a=1;
  b=2;
  label a="abcd";
  label b="ADer";
run;
data b;
  a=1;
  b=2;
  label a="abcd";
  label b="ADer";
run;

data _null_;
  set sashelp.vcolumn (where=(lowcase(name)='a')) end=last;
  call execute(cat('proc datasets library=',libname,' nolist nodetails;'));
  call execute(cat('modify ',memname,'; rename ',name,'=new_',name,';quit;'));
run;


SrikanthY
Calcite | Level 5
Variable name is not changed low-case to up-case

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ksharp
Super User

It depends on your OS, maybe you can't do it.

 

options validvarname=upcase;
data class;
 set sashelp.class;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Oh, not label, variable name.  In which case why?  It matters not to programming if they are upper/lower/mixed case.  If you have an output spec to match to then I would suggest creating an emtpy table which matches your spec, then setting your data to that spec.  This has the benefits of having a fixed structure, and you can pull out any problems:

proc sql;
  create table MYOUT 
  ( 
    VAR1 char(200),
    VAR2 num
  );
quit;

data myout;
  set myout processed data;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 12 replies
  • 3791 views
  • 9 likes
  • 7 in conversation