BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gladis6680
Obsidian | Level 7

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

HAVEWANT_1WANT_2WANT_3
1/1 EA11EA
1/1.9 LB11.9LB
1/1002 EA11002EA
1/19.97 LB119.97LB
1/3 KG13KG
27/235 ML27235ML
41/1.75 OZ411.75OZ
12/1.05 LT121.05LT
31/127 GR31127GR

 

Thank you so much.

1 ACCEPTED SOLUTION

Accepted Solutions
10 REPLIES 10
Reeza
Super User
SCAN can take multiple delimiters, can you post the code you tried.
Gladis6680
Obsidian | Level 7

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 

HAVEWANT_1WANT_2WANT_3
1/1 EA11 EA 
1/1.9 LB11.9 LB 
1/1002 EA11002 EA 
1/19.97 LB119.97 LB 
1/3 KG13 KG 
27/235 ML27235 ML 
41/1.75 OZ411.75 OZ 
12/1.05 LT121.05 LT 
31/127 GR31127 GR 
Tom
Super User Tom
Super User
want_1=scan(have,1,' /');
Gladis6680
Obsidian | Level 7

Thank you so much!!! that was easy

PeterClemmensen
Tourmaline | Level 20

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;
Gladis6680
Obsidian | Level 7

Thank you so much !!! So all I need to do is add the multiple delimiters in the inverted commas

Tom
Super User Tom
Super User

@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'?

Gladis6680
Obsidian | Level 7

sorry I meant (' ') quotation marks

Tom
Super User Tom
Super User

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.

Gladis6680
Obsidian | Level 7

Yes I understand, thank you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 3161 views
  • 1 like
  • 4 in conversation