BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WPH
Calcite | Level 5 WPH
Calcite | Level 5

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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' :),

 

%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

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

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;

 

Haikuo
Onyx | Level 15

Not entirely sure about your intention, is it value of the variable(see @PeterClemmensen'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;
WPH
Calcite | Level 5 WPH
Calcite | Level 5
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;


Haikuo
Onyx | Level 15

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;
WPH
Calcite | Level 5 WPH
Calcite | Level 5
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

Haikuo
Onyx | Level 15

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' :),

 

%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;

 

PeterClemmensen
Tourmaline | Level 20

Ah ok sorry, did not catch that 🙂

ShiroAmada
Lapis Lazuli | Level 10

I think something is wrong with this statement

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

 

Is OBS a dataset variable or a macro variable?

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
  • 8 replies
  • 15448 views
  • 1 like
  • 4 in conversation