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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

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

3 REPLIES 3
jklaverstijn
Rhodochrosite | Level 12

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.

Kurt_Bremser
Super User

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.

Stefy67
Calcite | Level 5
Thanks I find the solution.

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
  • 3 replies
  • 813 views
  • 0 likes
  • 3 in conversation