Use SAS Function Propcase
Use SAS Function Propcase
Use SAS Function Propcase
You might think I am crazy...but I have been using this macro for a long time to fix some contacts in my Google
Contacts...I get a little irritated when I can't find a particular person by email...so I wrote this macro...
This macro takes for Input a .csv file that is exported from Google Contacts and outputs a file that is ready to be imported
to Google Contacts....often I wanted to have Names in the proper case...
%macro organizeGoogleContacts(infile,outfile);
/*Import your contacts into SAS */
data googlegroups;
infile "&infile" dlm=',' dsd lrecl=32767 firstobs=2;
length Name GivenName AdditionalName Family_Name Yomi_Name Given_Name_Yomi
Additional_Name_Yomi Family_Name_Yomi Name_Prefix Name_Suffix Initials Nickname
Short_Name Maiden_Name Birthday Gender Location Billing_Information
Directory_Server Mileage Occupation Hobby Sensitivity Priority Subject Notes
Group_Membership E_mail_1___Type E_mail_1___Value Phone_1___Type
Phone_1___Value Phone_2___Type Phone_2___Value Phone_3___Type
Phone_3___Value Organization_1___Type Organization_1___Name Organization_1___Yomi_Name
Organization_1___Title Organization_1___Department Organization_1___Symbol
Organization_1___Location Organization_1___Job_Description $ 40;
input Name GivenName AdditionalName Family_Name Yomi_Name Given_Name_Yomi
Additional_Name_Yomi Family_Name_Yomi Name_Prefix Name_Suffix Initials Nickname
Short_Name Maiden_Name Birthday Gender Location Billing_Information
Directory_Server Mileage Occupation Hobby Sensitivity Priority Subject Notes
Group_Membership E_mail_1___Type E_mail_1___Value Phone_1___Type
Phone_1___Value Phone_2___Type Phone_2___Value Phone_3___Type
Phone_3___Value Organization_1___Type Organization_1___Name Organization_1___Yomi_Name
Organization_1___Title Organization_1___Department Organization_1___Symbol
Organization_1___Location Organization_1___Job_Description;
run;
/* For unnamed contacts use the Email username as the Name */
data names;
set googlegroups;
if name='' and E_mail_1___Value ne '' then name=propcase(lowcase(scan(E_mail_1___Value,1,'@')));/*Format the
names with camelcase*/
else name=propcase(upcase(name));/*Format the names with camelcase*/
run;
/* Remove any duplicates by name/email/phone contacts */
proc sort data=names out=googlecontacts nodupkey;
by name E_mail_1___Value Phone_1___Value;
where E_mail_1___Value ne '' or Phone_1___Value ne '';
run;
/* Many a times one contact may have been noted down with email contacts only */
proc sort data=googlecontacts out=email nodupkey;
by name;
where E_mail_1___Value ne '';
run;
/* Many a times one contact may have been noted down with Phone number only */
proc sort data=googlecontacts out=phone nodupkey;
by name;
where Phone_1___Value ne '';
run;
/* Merge the email and Phone contacts by name to get the email and phone on to one record */
data merged;
merge email phone;
by name;
run;
/* Export it out to Google csv once again... */
PROC EXPORT DATA= WORK.Merged
OUTFILE="&outfile"
DBMS=CSV REPLACE;
RUN;
/* Delete all Work datasets proactively */
proc datasets lib=work;
delete _all_;
quit;
%mend organizeGoogleContacts;
%let infile=C:\Documents and Settings\SASTechies\Desktop\google.csv;
%let outfile=C:\Documents and Settings\SASTechies\Desktop\GoogleContacts.csv;
%organizeGoogleContacts(&infile,&outfile);