I have data that look like this:
Chocolate chips (2)
Brown sugar (1)
Eggs 3
Flour (1)
Butter 2
And what I want is just:
Chocolate chips
Brown sugar
Eggs
Flour
Butter
Basically I want to retain all text prior to a digit or special character without compressing.
Thanks!
SCAN lets you specify your delimiters, try using all the digits and the opening parenthesis to see if that gives you what you need.
You can also look at the modifiers for slightly simpler code, but this should works.
data have;
input string_variable : & $40.;
cards;
Chocolate chips (2)
Brown sugar (1)
Eggs 3
Flour (1)
Butter 2
;;;;
run;
data want;
set have;
want = scan(string_variable, 1, "01234567890(");
run;
@Krysia24 wrote:
I have data that look like this:
Chocolate chips (2)
Brown sugar (1)
Eggs 3
Flour (1)
Butter 2
And what I want is just:
Chocolate chips
Brown sugar
Eggs
Flour
Butter
Basically I want to retain all text prior to a digit or special character without compressing.
Thanks!
SCAN lets you specify your delimiters, try using all the digits and the opening parenthesis to see if that gives you what you need.
You can also look at the modifiers for slightly simpler code, but this should works.
data have;
input string_variable : & $40.;
cards;
Chocolate chips (2)
Brown sugar (1)
Eggs 3
Flour (1)
Butter 2
;;;;
run;
data want;
set have;
want = scan(string_variable, 1, "01234567890(");
run;
@Krysia24 wrote:
I have data that look like this:
Chocolate chips (2)
Brown sugar (1)
Eggs 3
Flour (1)
Butter 2
And what I want is just:
Chocolate chips
Brown sugar
Eggs
Flour
Butter
Basically I want to retain all text prior to a digit or special character without compressing.
Thanks!
Thank you! I was using a combination of substr and index and wasn't quite getting what I wanted. Thanks again.
Another way is to COMPRESS out all the characters you don't want.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.