*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s2d1.sas ***;
dm "output;clear;log;clear";
Libname Course2 "C:\_SasCourse2006\Course2\SAS_Data";
proc print data=Course2.freqflyers; run;
data labels(keep=FullName Address1 Address2);
length FMName LName $ 10;
set Course2.freqflyers;
if substr(right(Id),6)='1' then
Title='Ms.';
else if substr(right(Id),6)='2' then
Title='Mr.';
FMName=scan(Name,2,',');
LName=scan(Name,1,',');
FullName=Title !! ' ' !! trim(FMName) !! ' ' !! LName;
Address2=scan(Address2,1,',') !! ', ' !!
scan(Address2,3,',') !! ' ' !!
scan(Address2,4,',');
run;
proc print data=labels noobs;
var FullName Address1 Address2;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s2d2.sas ***;
data labels(keep=FullName Address1 Address2);
length FMName LName $ 10;
set Course2.freqflyers;
if substr(right(ID),6)='1' then
Title='Ms.';
else if substr(right(ID),6)='2' then
Title='Mr.';
FMName=scan(Name,2,',');
LName=scan(Name,1,',');
FullName=catx(' ',Title,FMName,LName);
Address2=catx(' ',
scan(Address2,1,',') || ',',
scan(Address2,3,','),
scan(Address2,4,','));
run;
proc print data=labels noobs;
var FullName Address1 Address2;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s2d2+.sas ***;
data index;
Text="This target contains a BULL'S-EYE.";
Pos=find(Text,"BULL'S-EYE");
run;
Proc print data=index noobs; run;
data index1;
Text='DELIMIT IT WITH BLANKS.';
Pos1=find(Text,'IT');
Pos2=find(Text,' IT ');
Pos3=find(Text,'it');
Pos4=find(Text,'it','I');
run; /* ‘I’ ignores case */
Proc print data=index1 noobs; run;
data index2;
length String $ 5;
/* Length adds trailing blanks */
String='IT';
Text='DELIMIT IT WITH BLANKS.';
Pos5=find(Text,String);
Pos6=find(Text,String,'T');
Pos7=find(Text,' ' !! trim(String) !! ' ');
run; /* ‘T’ trims trailing blanks */
Proc print data=index2 noobs; run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s2d3.sas ***;
data silver(drop=Location);
length Year $ 4;
set Course2.ffhistory;
Status=propcase(Status,' ,');
Location=find(Status,'Silver');
if Location > 0;
SeatPref = propcase(SeatPref);
Year=substr(Status,Location+7,4);
run;
proc print data=silver noobs;
var Id Status Year SeatPref;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s2d4.sas ***;
data silver(drop=Location);
length Year $ 4;
set Course2.ffhistory;
Status=tranwrd(Status,'silver','Silver');
Location=index(Status,'Silver');
if Location > 0;
Year=substr(Status,Location+7,4);
run;
proc print data=silver noobs;
var ID Status Year SeatPref;
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d1.sas ***;
proc contents data=Course2.salary2; run;
proc print data=Course2.salary2; run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d2.sas ***;
data bonuses;
set Course2.salary2;
Bonus=.10*input(GrossPay,comma6.);
run;
proc print data=bonuses noobs;
title 'Results from conversion using the INPUT function';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d3.sas ***;
data bonuses(drop=CharGross);
set Course2.salary2(rename=(GrossPay=CharGross));
GrossPay=input(CharGross,comma6.);
Bonus=.10*GrossPay;
run;
proc contents data=bonuses;
title1 'Descriptor portion of BONUSES';
title2 'GROSSPAY variable is numeric';
run;
proc print data=bonuses noobs;
title1 'Data portion of BONUSES';
title2 'GROSSPAY variable is numeric';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d4.sas ***;
data birth(drop=Date);
set Course2.born;
Birthday=input(Date,date7.);
Age=int(yrdif(Birthday,'3may2008'd,
'ACT/ACT'));
run;
proc print data=birth noobs;
title 'Converting Character Dates to SAS Dates';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d5.sas ***;
proc contents data=Course2.phones; run;
proc print data=Course2.phones noobs; run;
data phonenumbers;
set Course2.phones;
Phone='(' !! Code !! ') ' !! Telephone;
run;
proc print data=phonenumbers noobs;
title 'Results from automatic conversion';
run;
*---+----1----+----2----+----3----+----4----+----5----+----6----+---;
*** c05s5d5.sas ***;
data phonenumbers(drop=NumCode Code);
set Course2.phones(rename=(Code=NumCode));
Code=put(NumCode,3.);
Phone='(' !! Code !! ') ' !! Telephone;
run;
proc contents data=phonenumbers;
title 'Descriptor portion of PHONENUMBERS';
run;
proc print data=phonenumbers noobs;
title 'Results from conversion using the PUT function';
run;