DATA Step, Macro, Functions and more

translate excel code into SAS code

Reply
Contributor
Posts: 65

translate excel code into SAS code

Can anybody translate this excel code IF(A6=A5,IF(B6=B5,IF(C6=C5,IF(D6<=E5+1,F5,F5+1),F5+1),F5+1),F5+1) into SAS code?

Thanks!

Super User
Posts: 19,878

Re: translate excel code into SAS code

Posted in reply to zhuxiaoyan1

You're better off converting that to a logic requirement and then someone can help implement the code in SAS. One to one conversion is rarely a good idea, there's possibly a totally different way of implementing this in SAS. 

 

It looks like you're incrementing based on some sort of logic by checking if the records are the same?

 

Sample input and output data are also very helpful, character vs numeric variables can affect how the solution is implemented.

 

Contributor
Posts: 65

Re: translate excel code into SAS code

Here is my data set. The Admit_ID is the variable I need to create.
Super User
Posts: 11,343

Re: translate excel code into SAS code

Posted in reply to zhuxiaoyan1

zhuxiaoyan1 wrote:
Here is my data set. The Admit_ID is the variable I need to create.

The attachment looks like it didn't make it.

In case you attempted a an Excel file many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

You can follow instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to turn you SAS data set into data step code that can be posted directly to the forum or attach as a text file.

Super User
Posts: 11,343

Re: translate excel code into SAS code

Posted in reply to zhuxiaoyan1

Do you have a SAS data set? Post a few rows of example input data from the SAS data set and the desired output.

 

Note that the the function in SAS to look at the value of a variable in a previous row is LAG.

Ask a Question
Discussion stats
  • 4 replies
  • 362 views
  • 3 likes
  • 3 in conversation