- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am analyzing data. I need to extract everything from these strings before the first space. How can I extract the substring of everything up to the first space. I am using SAS and have used PRXMATCH but not familiar with doing this. Thanks!
Removed
So in my output I need:
Removed
I then need to extract only the first numbers so I get:
Removed
Any help is greatly appreciated. Thanks much
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
string = scan(variablename,1,' ');
should do it. You should set the length of the target variable string before use though to a long enough value to hold expected results.
something like
length string $ 100;
string = scan(variablename,1,' ');
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input x $80.;
x1=scan(x,1,' ');
x2=scan(x,1,,'kd');
cards;
0518Audible adbl.co/bill NJ 01
06257-ELEVEN CHICAGO IL Purchase $33.30 Cash Back $10.00
0625#03345 JEWEL CHICAGO IL Purchase $58.58 Cash Back $20.00 00
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For those who may not have followed what Ksharp has done here:
1) The COUNT of 1 in the SCAN function means that we want to get the FIRST word from the string x. Since COUNT is POSITIVE, SCAN scans words from LEFT to RIGHT within the string x.
2) kd is a "SAS Character Function" that retains only numeric values from a string. Similarly, ak is a SAS Character Function that retains only alphabetical values from a string.
So here, kd would give us e.g. 06257 for x2 in the second row.
Had ak been used for x2, it would've given us e.g. ELEVEN instead.
The result for x1 here is 06257-ELEVEN