BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

 

I'm using the following code to format all my char variables so that they will appear as uppercase: 

 

proc datasets lib=work nolist;
    modify mydb;
    format _character_ $upcase.;
run;
quit;

1) While doing proc contents, the $UPCASE appears. Is it possible to prevent it appears in "Format"? Empty will be ok. 

2) Is there a way to exclude a specific char variable to be formatted as "upcase"?

 

Note that I used this code because I have many many variables and I cannot specify each one one by one.

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Item (1) makes no sense.  If you want to attach the $UPCASE. format so that the values print in uppercase then the format is attached.   

 

For (2) just add a second FORMAT statement that lists the variables that you want to have NO format attached to them.  That will remove any format that they might have had attached.

 

Example that removes the $UPCASE. format from the variable NAME.

proc datasets lib=work nolist;
  modify mydataset;
    format _character_ $upcase.;
    format name ;
  run;
quit;

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Item (1) makes no sense.  If you want to attach the $UPCASE. format so that the values print in uppercase then the format is attached.   

 

For (2) just add a second FORMAT statement that lists the variables that you want to have NO format attached to them.  That will remove any format that they might have had attached.

 

Example that removes the $UPCASE. format from the variable NAME.

proc datasets lib=work nolist;
  modify mydataset;
    format _character_ $upcase.;
    format name ;
  run;
quit;

 

Ksharp
Super User
As Tom said your first question doesn't make any sense, if you need to do that ,you could change all these variable value into upcase by UPCASE() function.
Tom
Super User Tom
Super User

@NewUsrStat wrote:

Hi guys, 

 

I'm using the following code to format all my char variables so that they will appear as uppercase: 

 

proc datasets lib=work nolist;
    modify mydb;
    format _character_ $upcase.;
run;
quit;

1) While doing proc contents, the $UPCASE appears. Is it possible to prevent it appears in "Format"? Empty will be ok. 

2) Is there a way to exclude a specific char variable to be formatted as "upcase"?

 

Note that I used this code because I have many many variables and I cannot specify each one one by one.

Thank you in advance


To your last point use some code generation instead so that you do not need to know the names of all of the variables. 

For example say you wanted to make a new dataset that converted all of the character variables except NAME to uppercase you could do something like this.

proc contents noprint data=mydb out=contents;
run;
filename code temp;
data _null_;
  set contents ;
  where type=2;
  where also upcase(name) ne 'NAME';
  file code;
  put name '=upcase(' name ');';
run;
data want;
  set mydb;
%include code / source2;
run;

Note to protect for nonstandard variable names in case you are running with VALIDVARNAME=ANY then you could modify the data _NULL_ code to generate name literals instead.

  nliteral=nliteral(name);
  put nliteral '=upcase(' nliteral ');';

 

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 458 views
  • 5 likes
  • 3 in conversation