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

Using SAS University Edition

 

How do i change a name linda Y. d'amora to a proper case name with the last name capital?

 

what am i doing wrong here?

 

data Uppercase;
set work.length;

String= upcase(String);
Name = propcase(Name);
run;

results.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
slater1
Fluorite | Level 6

@Tom wrote:

Is this some type of homework assignment?  What have you attempted? How did it go?  How was the result different than you wanted.

 

Also why did you go to the extra effort to take a PICTURE of your code and insert it into your message instead of just copying the TEXT of the code?  Not only was that harder for you it marks it impossible for someone to help you by just making minor edits to your code.


Nevermind, I figured it out. Thanks for all your help!
yes, this is a homework assignment. I need the last name in the D'amore to say D'Amore. I am new to programming and don't know the best way to complete stuff. So this is a work in progress for me. 

 

 

data Oscar;

length String $ 10 Name $ 20 Comment $25 Address $ 30 Q1-Q5 $ 1 ;
infile datalines dsd dlm= " ";
input String Name Comment Address Q1-Q5;

datalines;
AbC "jane E. MarPie" "Good Bad Bad Good" "25 River Road" y n N Y Y
12345 "Ron Cody" "Good Bad Ugly" "123 First Street" N n n n N
98x "Linda Y. d'amore" "No Comment" "1600 Penn Avenue" Y Y y y y
. "First Middle Last" . "21B Baker St." . . . Y N
;
*(2A)*Using the two length functions, compute the length of 'String' not counting
trailing blanks and the storage length of 'String'. Call these two variables L1 L2*;

data length;
set work.oscar;
L1=lengthn(String) + lengthn(String);
L2=lengthc(String) + lengthc(String);
findc(String, '2', '3')
run;

title 'Lengths of String';
proc print data=work.length;
run;

 

*(2B);
data Uppercase;
set work.length;

String= upcase(String);
Name = propcase(Name);
run;

 

title "Modified Program of Character Cases";
proc print data=work.uppercase;

run;

so when I run it like this, it does not change the D'amore to D'Amore. That is what I am trying to do. 

 

 

I have went back into the first part of the program and tried the

Name = Propcase(Name, " . ' ");

String = upcase(String);

 

it worked after I made some corrections. 

 

View solution in original post

16 REPLIES 16
Shmuel
Garnet | Level 18

Please post more examples of what you have and of what you want.

 

Please post a test date in the form of (use the running man icon on top):

data test;
  infile datalines;
        input name $20.;
datalines;
<string1>
<string2>
...
run;

 

slater1
Fluorite | Level 6

Capture.PNG

 

this is the program I started with

 

I am supposed to modify the program so that String is in uppercase and Name is in proper case.. Use appropriate delimiters so the name d'amore is spelled D'Amore.

 

PGStats
Opal | Level 21

Function propcase has some limitations, one of which is not handling apostrophes properly (no pun)

 

 71         data _null_;
 72         name = "jean-pierre d'entremont";
 73         pName = propcase(name);
 74         put _all_;
 75         run;
 
 name=jean-pierre d'entremont pName=Jean-Pierre D'entremont _ERROR_=0 _N_=1
PG
slater1
Fluorite | Level 6

Capture.PNG

 

this is the program I started with.

 

I am supposed to modify the program so that String is in uppercase and Name is in proper case. Using appropriate delimiters so that the name d'amore is spelled D'Amore.

 

Tom
Super User Tom
Super User

Is this some type of homework assignment?  What have you attempted? How did it go?  How was the result different than you wanted.

 

Also why did you go to the extra effort to take a PICTURE of your code and insert it into your message instead of just copying the TEXT of the code?  Not only was that harder for you it marks it impossible for someone to help you by just making minor edits to your code.

slater1
Fluorite | Level 6

@Tom wrote:

Is this some type of homework assignment?  What have you attempted? How did it go?  How was the result different than you wanted.

 

Also why did you go to the extra effort to take a PICTURE of your code and insert it into your message instead of just copying the TEXT of the code?  Not only was that harder for you it marks it impossible for someone to help you by just making minor edits to your code.


Nevermind, I figured it out. Thanks for all your help!
yes, this is a homework assignment. I need the last name in the D'amore to say D'Amore. I am new to programming and don't know the best way to complete stuff. So this is a work in progress for me. 

 

 

data Oscar;

length String $ 10 Name $ 20 Comment $25 Address $ 30 Q1-Q5 $ 1 ;
infile datalines dsd dlm= " ";
input String Name Comment Address Q1-Q5;

datalines;
AbC "jane E. MarPie" "Good Bad Bad Good" "25 River Road" y n N Y Y
12345 "Ron Cody" "Good Bad Ugly" "123 First Street" N n n n N
98x "Linda Y. d'amore" "No Comment" "1600 Penn Avenue" Y Y y y y
. "First Middle Last" . "21B Baker St." . . . Y N
;
*(2A)*Using the two length functions, compute the length of 'String' not counting
trailing blanks and the storage length of 'String'. Call these two variables L1 L2*;

data length;
set work.oscar;
L1=lengthn(String) + lengthn(String);
L2=lengthc(String) + lengthc(String);
findc(String, '2', '3')
run;

title 'Lengths of String';
proc print data=work.length;
run;

 

*(2B);
data Uppercase;
set work.length;

String= upcase(String);
Name = propcase(Name);
run;

 

title "Modified Program of Character Cases";
proc print data=work.uppercase;

run;

so when I run it like this, it does not change the D'amore to D'Amore. That is what I am trying to do. 

 

 

I have went back into the first part of the program and tried the

Name = Propcase(Name, " . ' ");

String = upcase(String);

 

it worked after I made some corrections. 

 

Reeza
Super User
Probably know this but names that have van in the middle that is usually lower case will not be correct.

Ie Johannes van der Waals
slater1
Fluorite | Level 6

I found this on SAS documentation on functions and

 

I went back into the first part of the program and tried the
Name = Propcase(Name, " . ' ");
String = upcase(String);
it worked after I made some corrections.

 

Thanks for your response.

Tom
Super User Tom
Super User

Re-reading the question was key as they provided the hint to the solution which you could find easily by reading the documentation.

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n169kj2of5nur0n1bl1hubv55q63.htm...

 

You should remind your instructor that getting the right case of names is not that easy.  Are you sure that "Linda Y. d'amore" actually uses D'Amore instead of d'Amore ,D'amore or d'amore?

slater1
Fluorite | Level 6
The answer was definitely not in my book for the class. This is supposed to be a beginner class. Far from it in my opinion.
Reeza
Super User
Use of functions such as SCAN() and PROPCASE()/UPCASE() are beginner level topics.
slater1
Fluorite | Level 6

Really, so I must be newer than a beginner. It is hard for me to remember all these functions.

Thanks for your help or response. 

Best wishes

Robin

Reeza
Super User

@slater1 wrote:

Really, so I must be newer than a beginner. It is hard for me to remember all these functions.

Thanks for your help or response. 

Best wishes

Robin


No one remembers them ever, I look up the definitions every day, especially because i program in multiple languages and want to ensure that I'm remembering it correctly for the language I'm using that day. 

 

Bookmark this page and when you need to do something, ie find a specific character that means use a character function. Then you click on character functions and see which one does what you want. If you're working with dates and want to know how to get the day of the month you would go to the Date & Time functions. Learning how to find things is more important. 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=allprodsle&docsetTarget=s...

 

EDIT: for example, I didn't know that PROPCASE takes a delimiter, but now I do, based on the code you used an a quick review of  the documentation on that function. 

hashman
Ammonite | Level 13

@slater1:

  1. Decompose the name using ' as a delimiter
  2. Propcase each decomposed chunk
  3. Put the chunks back together delimited by '

Such as:

data have ;                                                                                                                             
  input @1 Name $char32. ;                                                                                                              
  cards ;                                                                                                                               
jane E. MarPie                                                                                                                          
Jane e. marpie                                                                                                                          
Ron coDy                                                                                                                                
ron Cody                                                                                                                                
linda Y. d'amore of'love                                                                                                                
Linda y. D'amore                                                                                                                        
Linda y. d'Amore                                                                                                                        
Linda y. De'Amore                                                                                                                       
Linda y. dE'Amore                                                                                                                       
FirSt miDDle last                                                                                                                       
f'firSt m'Middle lA'last                                                                                                                
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want (drop = _:) ;                                                                                                                 
  set have (rename=name=_nm) ;                                                                                                
  name = _nm ; *set syslength;                                                                                                                          
  name = "" ;                                                                                                                           
  do _i = 1 to countw (_nm, "'") ;                                                                                            
    name = catx ("'", name, propcase (scan (_nm, _i, "'"))) ;                                                                           
  end ;                                                                                                                                 
run ;                        

Kind regards

Paul D.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 3468 views
  • 4 likes
  • 6 in conversation