Hi SAS Community,
I have a this table below with 2 delimiters, I tried the SCAN function but it did not work. Can I please get some help on this
HAVE | WANT_1 | WANT_2 | WANT_3 |
1/1 EA | 1 | 1 | EA |
1/1.9 LB | 1 | 1.9 | LB |
1/1002 EA | 1 | 1002 | EA |
1/19.97 LB | 1 | 19.97 | LB |
1/3 KG | 1 | 3 | KG |
27/235 ML | 27 | 235 | ML |
41/1.75 OZ | 41 | 1.75 | OZ |
12/1.05 LT | 12 | 1.05 | LT |
31/127 GR | 31 | 127 | GR |
Thank you so much.
want_1=scan(have,1,' /');
Hi there, this is what I tried
data HAVE |
set WANT; |
length WANT_1 $10 WANT_2 $10 WANT_3 $10; |
WANT_1=scan(HAVE, 1, '/'); |
WANT_2=scan(HAVE, 2, '/'); |
WANT_3=scan(HAVE, 3, ' '); |
run; |
I got
HAVE | WANT_1 | WANT_2 | WANT_3 |
1/1 EA | 1 | 1 EA | |
1/1.9 LB | 1 | 1.9 LB | |
1/1002 EA | 1 | 1002 EA | |
1/19.97 LB | 1 | 19.97 LB | |
1/3 KG | 1 | 3 KG | |
27/235 ML | 27 | 235 ML | |
41/1.75 OZ | 41 | 1.75 OZ | |
12/1.05 LT | 12 | 1.05 LT | |
31/127 GR | 31 | 127 GR |
want_1=scan(have,1,' /');
Thank you so much!!! that was easy
The SCAN Function can handle this?
data have;
input HAVE $20.;
datalines;
1/1 EA
1/1.9 LB
1/1002 EA
1/19.97 LB
1/3 KG
27/235 ML
41/1.75 OZ
12/1.05 LT
31/127 GR
;
data want;
set have;
want_1=scan(HAVE, 1, '/ ');
want_2=scan(HAVE, 2, '/ ');
want_3=scan(HAVE, 3, '/ ');
run;
Thank you so much !!! So all I need to do is add the multiple delimiters in the inverted commas
@Gladis6680 wrote:
Thank you so much !!! So all I need to do is add the multiple delimiters in the inverted commas
🙂 🙂
What the heck is an 'inverted comma'?
sorry I meant (' ') quotation marks
Note that in SAS code you can use either the single quote character or the double quote character to enclose string literals. Not sure if there is a similar goofy name that people use for the double quote character.
Yes I understand, thank you
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.