BookmarkSubscribeRSS Feed

If there is a list of values (copied from excel or dataset or text file) that need to be used in where condition, strings need to be in quotes separated by comma. How about giving power to Find & Replace in SAS EG (Ctrl+H) like Notepad++ does.

 

For example I have:
Acura 
Audi 
BMW 
Buick 
Cadillac 
Chevrolet 
Chrysler 
Dodge 
Ford 

I want them : 
"Acura","Audi","BMW","Buick","Cadillac","Chevrolet","Chrysler","Dodge","Ford"

Step 1:

Open notepade++ and paste the values.

Step 2:

Remove leading and trailing blanks: Go to edit->Blank Operations->Trim leading and trailing space.

Step 3:

Put quotes: Open Search>Replace… in Notepad++ (Ctrl+H)

Select Regular Expression and in find what add (.+) and in replace what add “\1” and click replace. This will add quotes to the words listed in the file when replaced.image.png

 

 

Step 4

Separate by comma: Now in Find what add \r\n and in Replace with add just comma (,) as shown in screenshot.  image.png

 

 

 

8 Comments
data_null__
Jade | Level 19

Why not have your program access the data directly?  Think of ways to separate the code and the data.

Tom
Super User
Super User

Personally I just use my SAS macro that converts a list into quoted list.

where make in %qlist(
Acura 
Audi 
BMW 
Buick 
Cadillac 
Chevrolet 
Chrysler 
Dodge 
Ford 
) 

No need to edit the source code.

FreelanceReinh
Jade | Level 19

I like using powerful editor functions. Not sure about SAS EG (which I don't use), but most of this functionality is available in the SAS Enhanced Editor (and has been for many years):

 

Step 1: Not necessary to open another program. Paste directly into Enhanced Editor.

 

Step 2: Select the list. Remove leading blanks (if any) with Shift+Tab, trailing blanks with Ctrl+Shift+W.

 

Step 3: Press Tab to indent the selected lines by one space (assumes suitable tab settings in Enhanced Editor Options) and replace that space (i.e. all spaces in the first column) by a quotation mark (Ctrl+H, ..., "Replace in Selection" as usual). If embedded blanks were present ("Land Rover"), the blank in "Find text" could be preceded by "^" in conjunction with "Regular expression search".

 

Step 4: Replace line breaks (Find text:\n) with quotation mark followed by blank using "Regular expression search", "Replace in Selection". The comma is not required in the WHERE condition anyway. I used blank instead to avoid the unwanted comma after "Ford" (assuming a line break after "Ford" in the selection).

 

Done. (No need for "Step 5: Copy and paste from Notepad++ to SAS".)

BillSawyer
SAS Employee

I reduced the process to a single shortcut key.

 

While in the EG program editor window, you can click the Program menu > Editor Macros > Record New.

 

Then, do all the steps provided by FreelanceReinhard then click Program > Editor Macros > Stop Recording.

 

You are then prompted to name the Keyboard macro and to assign a shortcut key.

 

Now, when you select a new list of values all you have to do is click your shortcut key, and it does the work for you.

 

Regards,

Bill

 

 

 

SuryaKiran
Meteorite | Level 14

Thanks @FreelanceReinh and @BillSawyer, this is good to know. Although it is not as same as how it's done in Notepad++ but the result will be the same. Additionally assigning it a shortcut key saves time.  

DaveShea
Lapis Lazuli | Level 10

I agree with the idea of beefing-up the Find/Replace within SAS Enterprise Guide. I would like to see some of the power that Notepad++ offers integrated into our SAS Enterprise Guide code editor. Certainly, for me, the [Replace in Selection] button that is already available, is a work of genius for which I believe the developer can be truly proud, it has saved me a LOT of time and error.

 

However, adding some of the Notepad++ Find/Replace features would make my SAS Code Editor life a whole lot more productive.

 

My favourite from Notepad++ (v7.3.3), which does NOT involve me beating myself up to write a Regular Expression, is the simple way of looking for occurrences of several strings at once. For example using this value in the Notepad++ Find dialog box:

 

(kumquat|biffo|dandy|broccoli)

and ensuring that the Search Mode is set to Regular Expression.

 

If we could have this sort of feature implemented in the SAS Enterprise Guide code editor Find/Replace I would be a happy man.......for a while Cat Happy

 

Cheers,

 

Downunder Dave

 

SuryaKiran
Meteorite | Level 14

@DaveShea what version of SAS EG are you using. I was able to do as you said in my SAS EG 7.15 HF2 (64bit).

 

image.png

DaveShea
Lapis Lazuli | Level 10

Hi SuryaKiran,

 

Well, well, well, I learn new things everyday !

 

Thanks for pointing out that SAS Enterprise Guide already offers that multi-string search capability. It had never dawned on me to ensure that the [Regular Expression] check box was set to ON, especially after I banged on about doing exactly the same thing in Notepad++ Smiley Embarassed.

 

2018-11-07_09h28_17.png

 

I've got a new tool in my toolbox, thank you.

 

Cheers,

 

Downunder Dave.