DATA Step, Macro, Functions and more

Recoding variable with contains instruction

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Recoding variable with contains instruction

Hi,

I wish to create a new variable Newcode using conditions and "Contains" instruction.

Considering the example here attached  the variable Newcode has to satisfy this condition :

 

if (ateco81='830' or ateco81='982') and (ateco91='93020' or ateco91='93021') and (attsoc contains "PArrucch*" or "Barbier*")) then Newcode ='999';

Obviously this instruction doesn't work. Can you give me any suggestion?

Thanks

Stefania

 

Version SAS 9.4 


Accepted Solutions
Solution
‎03-21-2018 10:01 AM
Valued Guide
Posts: 530

Re: Recoding variable with contains instruction

As usual there is more than one way to do this. The quickest would be to use the FIND function:

 

if find(string, substr) > 0 then ...

Alternatives are the INDEX function and Perl Regular Expressions (PRX) functions.

 

Hope this helps,

 - Jan.

View solution in original post


All Replies
Solution
‎03-21-2018 10:01 AM
Valued Guide
Posts: 530

Re: Recoding variable with contains instruction

As usual there is more than one way to do this. The quickest would be to use the FIND function:

 

if find(string, substr) > 0 then ...

Alternatives are the INDEX function and Perl Regular Expressions (PRX) functions.

 

Hope this helps,

 - Jan.

Super User
Posts: 9,611

Re: Recoding variable with contains instruction

Please supply code as advised in https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce, and example data in data steps with datalines (a macro for converting your data to data steps is found in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...)

Posting Excel files automatically reduces the number of potential helpers, as many of us won't (or even can't, by organizational policies) download MS Office files from the web.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 7

Re: Recoding variable with contains instruction

Posted in reply to KurtBremser
Thanks I find the solution.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 91 views
  • 0 likes
  • 3 in conversation