DATA Step, Macro, Functions and more

creating an Indicator

Reply
Contributor
Posts: 21

creating an Indicator

I am trying to code if a auditor_fkey=222 then companyIND=1.

 

For example if CompanyX is audited by auditor_fkey 222 in 2001, I need the companyIND to show up for that CompanyX regardless of the year (every time the company is in the database). 

 

The issue I am running into is I need that 1 to show up for each time the company (company_fkey) was audited by a certain auditor based on the auditor_fkey.

 

Thank you! 

Trusted Advisor
Posts: 1,312

Re: creating an Indicator

Show us data you have, and data you want.  I'm not convinced I understand what you want.

Contributor
Posts: 21

Re: creating an Indicator

Super User
Posts: 13,358

Re: creating an Indicator


@dlazer1 wrote:

I am trying to code if a auditor_fkey=222 then companyIND=1.

 

For example if CompanyX is audited by auditor_fkey 222 in 2001, I need the companyIND to show up for that CompanyX regardless of the year (every time the company is in the database). 

 

The issue I am running into is I need that 1 to show up for each time the company (company_fkey) was audited by a certain auditor based on the auditor_fkey.

 

Thank you! 


You in your example if audited in 2001. Would you need to have that apply for years prior to 2001?

If that is the case then something like this:

proc sql;
   create table want as
   select a.*, ( not missing(b.company_fkey)) as companyIND
   from have as a
        left join
        (select company_fkey from have
         where auditor_fkey=222) as b
       on a.company_fkey=b.company_fkey
   ;
quit;
Contributor
Posts: 21

Re: creating an Indicator

This did not output what I'm looking for. 

 

Here is an example and the indicator is how I need it coded. Basically if any year, an auditor_fkey for any company_fkey is there, then there needs to be an indicator.

 

 

Super User
Posts: 13,358

Re: creating an Indicator


@dlazer1 wrote:

This did not output what I'm looking for. 

 

Here is an example and the indicator is how I need it coded. Basically if any year, an auditor_fkey for any company_fkey is there, then there needs to be an indicator.

 

 


No actual input data

No actual example output

And your document doesn't actually clear much up as you don't show where the desired "auditor_fkey" values to select come from or use to create the indicators might be.

You show values of auditor_fkey of

xxxxxx50

2

xxxxxx51

xxxxxx52

1

 

HOW in a generic sense as in a programmable rule are we to derive that the only auditor_fkey values you want are

xxxxxx50

xxxxxx51

xxxxxx52

 

If the rule is any auditor_fkey that start with xxxxxx then state that as part of the processing logic. IF your xxxxxx are actually masking critical information that changes from record to record then we need to know that as well.

 

Did the example I provided work for that stated auditor_fkey value? If not then you need to provide lots more information about why not:

 

"This did not output what I'm looking for" is awful vague especially since there was no example provided of the desired output.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Contributor
Posts: 21

How to code if a company has been associated with another company?

I am trying to figure out how to do an indicator variable for any company_fkey that has ever been associated with a particular auditor_fkey. 

 

Thank you!

SAS Moderator
Posts: 56

Re: How to code if a company has been associated with another company? [how to improve your question]

Hello @dlazer1,


Your question requires more details before experts can help. Can you revise your question to include more information? 

 

Review this checklist:

  • Specify a meaningful subject line for your topic.  Avoid generic subjects like "need help," "SAS query," or "urgent."
  • When appropriate, provide sample data in text or DATA step format.  See this article for one method you can use.
  • If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition. Use the Photos button to include the image in your message.
    use_buttons.png
  • It also helps to include an example (table or picture) of the result that you're trying to achieve.

To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message.  From there you can adjust the title and add more details to the body of the message.  Or, simply reply to this message with any additional information you can supply.

 

edit_post.png

SAS experts are eager to help -- help them by providing as much detail as you can.

 

This prewritten response was triggered for you by fellow SAS Support Communities member @PGStats

.
Ask a Question
Discussion stats
  • 7 replies
  • 127 views
  • 0 likes
  • 4 in conversation