DATA Step, Macro, Functions and more

Coding

Reply
Occasional Contributor
Posts: 19

Coding

I have a dataset with Excercise (options - C1, C2), Dates, SSN, drinks (options - coke, sprite).

I want to flag a client who on the same day he excercises also buys either coke, sprite or both drinks.

Any help with sas codes please

Super User
Posts: 11,343

Re: Coding

One generic answer is in a data step something like

 

if exercisevariable = value and drinksvariable in (cokevalue, spritevalue) then flag= 1;

 

with out knowing 1) actual variable names, 2) actual variable values it is hard to get more specific.

 

Occasional Contributor
Posts: 19

Re: Coding

How do we factor in the SSN and the date for each person
Super User
Posts: 11,343

Re: Coding

Time to provide some example start data and what you want for a result. PLEASE do not provide any actual SSN values.

And it is best to provide example data in the form of a data step that replicates all of the properties of your data. 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.

Without such details we have to make assumptions about your data and could arrive at solutions that do not work because it relies on the value being one type and your actual data is a different type.

 

You would need to provide examples of how you think you want to use the dates, probably needing to ensure that your DATES are SAS date valued variables.

Occasional Contributor
Posts: 19

Re: Coding

Sure thx
Ask a Question
Discussion stats
  • 4 replies
  • 162 views
  • 1 like
  • 2 in conversation