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

I have been trying to figure it out how to solve this question for two days but no luck yet.  Hope you can help.

 

Q)  Convert all consonants in the values for the City and Team variables to uppercase letters and all vowels in the values for the City and Team variables to lowercase letters.

Note: Overwrite the original values with the new values   Refer the detail to the attachment.

 

 

infile ' /home/coccus030/sasuser.v94/nfldata2.txt' firstobs=2;
*/ @20 to indicate SAS to read at 20  city and year are too close to each other;
input City & $16. @20 Year Team $;
Spacec = city;
if index (strip(city),'') >0 then spacec =1;
else spacec = 0;
Spacet = Team;
if index (strip(team),'')>0 then spacet = 1;
else Spacet = 0;
Numbert = team;
*anydigit look for number;
if anydigit (team) then numbert =1;
else numbert = 0;
CityTeam = catx('-',city,team);


array CTL (3) $ city Team Cityteam;

do lowcase = 1 to substr('City',2,1);

If substr(lowcase(City),2,1) in ('a','e','i','o','u') then CTL (lowcase) = lowcase;
else CTL (lowcase) = upcase;


end;
superbowl = city;
if team = 'Giants' then superbowl = 'Winner';
else superbowl = 'not a contender';

run;

 

Txt

----+----1----+----2----+----3
Baltimore 2012 Ravens
Cincinnati 2012 Bengals
Cleveland 2012 Browns
Pittsburgh 2012 Steelers
Chicago 2012 Bears
Detroit 2012 Lions
Green Bay 2012 Packers

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I would do:

 

data sports;
  length City $15 Team $12;
  infile datalines dlm=',' dsd;
  input @1 City $ year Team $;
from = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
to =   "aBCDeFGHiJKLMNoPQRSTuVWXyZ";
city = translate(upcase(city),to,from);
team = translate(upcase(team),to,from);
drop from to;
datalines;
Baltimore, 2012, Ravens
Cincinnati, 2012, Bengals
Cleveland, 2012, Browns
Pittsburgh, 2012, Steelers
Chicago, 2012, Bears
Detroit, 2012, Lions
Green Bay, 2012, Packers
;

proc print; run;
PG

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  I agree with a DO loop, I'm not sure you need an ARRAY, since the TRANSLATE function will work for you. I did not consider 'y' to be a vowel for this example. Also, I did NOT overwrite the original values because I wanted to show my work in progress (TmpStr, NewCity and NewTeam):

upcase_lowcase.png

 

Cynthia

 

  Here's the code I used:

data sports;
  length City NewCity $15 Team NewTeam $12 TmpStr  $30 uchar $1;
  infile datalines dlm=',' dsd;
  input @1 City $ year Team $;
  TmpStr=upcase(catx('~',City,Team));
  do ck = 'a', 'e', 'i', 'o', 'u';
    uchar = upcase(ck);
    TmpStr = translate(TmpStr,ck,uchar);
  end;
  NewCity = scan(TmpStr,1,'~');
  NewTeam = scan(TmpStr,2,'~');
return;
datalines;
Baltimore, 2012, Ravens
Cincinnati, 2012, Bengals
Cleveland, 2012, Browns
Pittsburgh, 2012, Steelers
Chicago, 2012, Bears
Detroit, 2012, Lions
Green Bay, 2012, Packers
;
run;
  
proc print data=sports;
var City NewCity year Team NewTeam TmpStr;
run;
PGStats
Opal | Level 21

I would do:

 

data sports;
  length City $15 Team $12;
  infile datalines dlm=',' dsd;
  input @1 City $ year Team $;
from = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
to =   "aBCDeFGHiJKLMNoPQRSTuVWXyZ";
city = translate(upcase(city),to,from);
team = translate(upcase(team),to,from);
drop from to;
datalines;
Baltimore, 2012, Ravens
Cincinnati, 2012, Bengals
Cleveland, 2012, Browns
Pittsburgh, 2012, Steelers
Chicago, 2012, Bears
Detroit, 2012, Lions
Green Bay, 2012, Packers
;

proc print; run;
PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 876 views
  • 1 like
  • 3 in conversation