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

Hi,

 

I have data set and want to select particular contents from variables and want to update desire value in another variable. 

 

Example-

 

data test;

input id category

cards;

11BRG234

12IMF456

run; 

 

expecting below result in data

 

Id                 Category

11BRG234   Broker

12IMF456    Agent

 

Please suggest

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
data want;
  set test;
  if find(id,'BRG') then category = 'Broker';
run;

View solution in original post

5 REPLIES 5
sanjaymane7
Obsidian | Level 7
I have 14 lakh observations in above dataset. Want to select content 'BRG' from Id and update category accordingly
mkeintz
PROC Star

 

You apparently want all observations with the string "BRG" in the id variable:

 

data want;
  set test;
  where find(id,'BRG');
run;

which filters through all observations in which the FIND function returns a non-zero value.   Since the FIND function returns the character position at which the string 'BRG' appears in the id variable.  It returns a zero when the string is not found.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sanjaymane7
Obsidian | Level 7
Thanks. After this filter, I want write as 'broker' in another column/ variable.
SASKiwi
PROC Star
data want;
  set test;
  if find(id,'BRG') then category = 'Broker';
run;
sanjaymane7
Obsidian | Level 7
Hi, It works. Thank you so much

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 632 views
  • 0 likes
  • 3 in conversation