BookmarkSubscribeRSS Feed
dlazer1
Calcite | Level 5

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! 

7 REPLIES 7
dlazer1
Calcite | Level 5

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!

Community_Guide
SAS Moderator

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

.
mkeintz
PROC Star

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

--------------------------
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

--------------------------
dlazer1
Calcite | Level 5
 
ballardw
Super User

@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;
dlazer1
Calcite | Level 5

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.

 

 

ballardw
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1344 views
  • 0 likes
  • 4 in conversation