@skavli wrote:
Hi y'all i hope you're doing fine,
I'm working on a cars database and i'm having a little hard time extract name and surname of cars, my table looks like this :
Brand
CITROEN C3 AIRCROSS
DS3 CROSSBACK E-TENSE
OPEL GRANDLAND X
Now i wanna create two variables one named Make ( for the brand name ) and the other Model (for the brand model), so far so good for the Make ( because it's the first string before the space ) so with this i've succeeded getting my Make
Make = scan(brand,1,' ');
Now it's a little bit harder to for the model i've had few ideas but none was effective, for my model variable i want everything after the first space, i thought first to ease the process use tranwrd function and replace all my spaces with a underscore but it replaces also the space in the end with underscore, for the substr function i need the position for each observation wich a little bit hard since each observation is different.
Do you have any hint for me to make this work and all the strings after the first space please ?
Edit your original post, using a SAS datastep with datalines statements to create your sample dataset. Don't paste in a screenshot since if forces *us* to create *your* sample dataset. Post using the "Insert SAS code" icon.
data have;
length somevariable $200;
somevariable='foo bar blah';
run;
data want1;
set have;
length make $100 model $100;
pos=index(somevariable,' ');
if pos then do;
make=substr(somevariable,1,pos);
model=substr(somevariable,pos+1);
model=strip(model);
end;
run;
data want2;
set have;
length make $100 model $100;
rx=prxparse('/(.*?) (.*)/o');
if prxmatch(rx,somevariable) then do;
make=prxposn(rx,1,somevariable);
model=prxposn(rx,2,somevariable);
end;
run;
... View more