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

How does one identify 0 or more spaces? I thought that the following would work, but it fails for the 2nd record ("Jones,  Fred") because the , and F are separated by two spaces. It works for all of the other records.

data ReversedNames;

   input name & $32.;

   datalines;

Smith,Tom

Jones,  Fred

Kavich, Kate

Turley, Ron

Dulix, Yolanda

;

/* Reverse last and first names with a DATA step. */

data names;

   set ReversedNames;

   name = prxchange('s/(\w+),\s*(\w+)/$2 $1/', -1, name);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

Art,

There is no issue with your regular expression.  The issue is with your reading of the ReversedNames cards.  & will only move past the first space with list input.

filename ft15f001 temp;

data ReversedNames;

   length name $ 32;

   infile ft15f001 length=len;

   input @1 name $varying. len;

   list;

   parmcards;

Smith,Tom

Jones,  Fred

Kavich, Kate

Turley, Ron

Dulix, Yolanda

;

View solution in original post

2 REPLIES 2
FriedEgg
SAS Employee

Art,

There is no issue with your regular expression.  The issue is with your reading of the ReversedNames cards.  & will only move past the first space with list input.

filename ft15f001 temp;

data ReversedNames;

   length name $ 32;

   infile ft15f001 length=len;

   input @1 name $varying. len;

   list;

   parmcards;

Smith,Tom

Jones,  Fred

Kavich, Kate

Turley, Ron

Dulix, Yolanda

;

art297
Opal | Level 21

Matt,

Thanks! While I've obviously forgotten things I know, at least I'm FINALLY getting around to learning at least a little about regular expressions!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 763 views
  • 2 likes
  • 2 in conversation