Home > OS >  Extracting first letter of each word in SAS Programming
Extracting first letter of each word in SAS Programming

Time:09-21

data have;
input full_names 50.;
datalines;
Austin Richard Post
Quavious Keyate Marshall
David John McDonald
Jonathan Lyndale Kirk
;
run;

Required output first letter of each word as follows

ARP QKM DJM JLK

CodePudding user response:

This should work. Also, you have an error in data have, as you have a character variable, not numeric one (and you declared numeric one).

data have;
input full_names $50.;
datalines;
Austin Richard Post
Quavious Keyate Marshall
David John McDonald
Jonathan Lyndale Kirk
;
run;

data want;
    set have;
    first_letters=cats(substr(scan(full_names,1),1,1),substr(scan(full_names,2),1,1),substr(scan(full_names,3),1,1));
run;
  • Related