DATA Step, Macro, Functions and more

UPPERCASE AND LOWERCASE

Accepted Solution Solved
Reply
New Contributor WPH
New Contributor
Posts: 4
Accepted Solution

UPPERCASE AND LOWERCASE

Hi all,

 

I am quite new here as SAS user and i need your help.

 

Is there any code to identify the variable, if its lowercase or uppercase? Without looking into sashelp.vcolumn?

 

My goal is, i want to make a list which variable that already uppercase and which one are not.

 

btw i use SAS enterprise guide

 

Thank you for your help

 

WPH 


Accepted Solutions
Solution
‎09-20-2017 10:25 AM
Respected Advisor
Posts: 3,167

Re: UPPERCASE AND LOWERCASE

[ Edited ]

You are a fresh SAS user, I suggest you progress one step at a time. I would try to learn how to write plain SAS code as the first step, then I will learn how to delivery it (Macro). As a rule of thumb, advoid mixing SAS code and Macro like you did. Here, when I say 'wrap my code', I mean 'wrap my code' as is, not 'modify my code then wrap it' Smiley Happy,

 

%MACRO check_upcase;
data _null_;
set sashelp.vcolumn;
WHERE memname EQ 'ADAE' AND libname EQ 'DERIVED';
IF upcase(name)NE name 
then put "WARNING: Please check the dataset check_upcase. Some variable its not UPCASE.";
run; %MEND check_upcase; %check_upcase;

 

View solution in original post


All Replies
PROC Star
Posts: 1,215

Re: UPPERCASE AND LOWERCASE

[ Edited ]

Perhaps something like this?

 

Compare the variable to its upcase equivalent and output accordingly.

 

data have;
input charvar$;
datalines;
Hello
HELLO
;

data Upcase notUpcase;
	set have;
	if upcase(charvar)=charvar then output Upcase;
	else output notUpcase;
run;

 

Respected Advisor
Posts: 3,167

Re: UPPERCASE AND LOWERCASE

Not entirely sure about your intention, is it value of the variable(see @draycut's solution), or is it the name of the variable, since you mentioned metadata 'vcolumns'. SAS, in operation, does not care the case of the variables, however, you can still put it out as being shown below:

 

data want;
	set sashelp.class(keep=age); /*Age came in as Proper case variable*/
	AGE_UP=age;/*upper case variable name*/
	age_low=age;/*lower case variable name*/
	array _age age:;
	array po proper upper lower;

	do over _age;
	/*the show the position of first lower case in the varialble name*/
		po=anylower(vname(_age));/*you can also use anyupper() for this purpose*/
	end;
run;
New Contributor WPH
New Contributor
Posts: 4

Re: UPPERCASE AND LOWERCASE

Hi Haikuo and Draycut

Thank you for your response.

My intention was the name of the variable. I have created some macro, could you please take a look. What do you think?

%MACRO check_upcase;
PROC SQL;
CREATE TABLE check_01 AS
SELECT *
FROM sashelp.vcolumn
WHERE memname EQ 'ADAE' AND libname EQ 'DERIVED';
QUIT;
DATA notupcase;
set check_01;
IF upcase(name)NE name THEN OUTPUT notupcase;
RUN;
%IF obs. >0 %THEN %DO;
%PUT %SYSFUNC( CATT(WARNING: Please check the dataset check_upcase. Some variable its not UPCASE. )) ;
%END;
%MEND check_upcase;
%check_upcase;


Respected Advisor
Posts: 3,167

Re: UPPERCASE AND LOWERCASE

[ Edited ]

Not sure why you need a macro, but your code is unnecessarily complicated, you can wrap up the following code in a macro:

 

data _null_;
set sashelp.vcolumn;
WHERE memname EQ 'ADAE' AND libname EQ 'DERIVED';
IF upcase(name)NE name 
then put "WARNING: Please check the dataset check_upcase. Some variable its not UPCASE.";
run;
New Contributor WPH
New Contributor
Posts: 4

Re: UPPERCASE AND LOWERCASE

Hi Haikuo,

I try to wrap up your code in the macro, please see

%MACRO check_upcase;
data _null_;
set sashelp.vcolumn;
WHERE memname EQ 'ADAE' AND libname EQ 'DERIVED';
%IF upcase(name)NE name %then %DO;
%put %SYSFUNC( CATT( WARNING: Please check the dataset check_upcase Some variable its not UPCASE));
%END;
%MEND check_upcase;
%check_upcase;


Unfortunately come this error message, could you help me please

The SAS System

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
ERROR: Required operator not found in expression: upcase(name)NE name
ERROR: The macro CHECK_UPCASE will stop executing.
39 ;*';*";*/;quit;run;
____
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

Solution
‎09-20-2017 10:25 AM
Respected Advisor
Posts: 3,167

Re: UPPERCASE AND LOWERCASE

[ Edited ]

You are a fresh SAS user, I suggest you progress one step at a time. I would try to learn how to write plain SAS code as the first step, then I will learn how to delivery it (Macro). As a rule of thumb, advoid mixing SAS code and Macro like you did. Here, when I say 'wrap my code', I mean 'wrap my code' as is, not 'modify my code then wrap it' Smiley Happy,

 

%MACRO check_upcase;
data _null_;
set sashelp.vcolumn;
WHERE memname EQ 'ADAE' AND libname EQ 'DERIVED';
IF upcase(name)NE name 
then put "WARNING: Please check the dataset check_upcase. Some variable its not UPCASE.";
run; %MEND check_upcase; %check_upcase;

 

PROC Star
Posts: 1,215

Re: UPPERCASE AND LOWERCASE

Ah ok sorry, did not catch that Smiley Happy

Frequent Contributor
Posts: 113

Re: UPPERCASE AND LOWERCASE

I think something is wrong with this statement

"%IF obs. >0 %THEN %DO;"

 

Is OBS a dataset variable or a macro variable?

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 408 views
  • 1 like
  • 4 in conversation