BookmarkSubscribeRSS Feed
saitejaguduru97
Calcite | Level 5

Hi All,

 

Please help me in the programming for the below Questions:-

 

Question 1 

Write a simple macro (SAS) to take an input dataset (sample rows below) as parameter and calculate the time duration (in days) for which a patient was prescribed a particular therapy.

Macro should have 2 parameter -input and output dataset

Sample Input:  Table_A                                                  Output data: Table_B

Pat Id

Drug

Prescription date

  

Pat Id

Drug

Days on treatment

1001

A

1-Jan-22

  

1001

A

12

1001

A

12-Jan-22

  

1001

B

1

1001

B

1-Mar-22

  

1002

C

11

1002

C

4-Jan-22

  

 

1002

C

14-Jan-22

  

 

 

Note: Please assume a patient is continued on a particular therapy if there is next prescription available. Also ignore days’ supply calculation.

- - - - - -- - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - -- - - - -

Type solution to Question here:

 

 

Question 2 

There are two table as shown below.

Table 1 – consists of patient’s demographics info (consists info of the entire population)

Table 2- consist of patient’s diagnosis info. Find sample rows of the dataset below.

Sample Tab1:                                       Sample Tab 2:

Pat Id

Sex

Age

 

 

Pat Id

Diagnosis

Date

1001

M

30

 

 

1001

RA

1-Jan-22

1002

M

75

 

 

1002

PSA

2-Jan-22

1003

M

34

 

 

1003

PSO

3-Jan-22

1004

F

15

 

 

1004

IBD

4-Jan-22

1005

F

16

 

 

1006

RA

5-Jan-22

 

Prepare code to calculate prevalence of IBD diagnosis stratified by Sex.

Prevalence: the proportion of a population with a disease  or a particular condition over a specified period of time (period prevalence).

Formula:  prevalence = (no of cases of illness) / (total population)

Sample output data:

Sex

Number of IBD patients (n)

Number of total Population (N)

Prevalence (n/N)

  
  

M

99

1000

0.099

  

F

20

100

0.2

  

M

190

1111

0.17

  

F

30

100

0.3

  

 

 

Type solution to Question here:

 

 

 

 

Question 3 

Each node in the tree can be one of three types:

  • "Leaf": if the node is a leaf node.
  • "Root": if the node is the root of the tree.
  • "Inner": If the node is neither a leaf node nor a root node.

Example

saitejaguduru97_0-1674034982571.jpeg

 

  • Root (as no parent node available)
  • Inner (as both parent and child node available)
  • 5 leaf nodes (as no further branches are available)

Write an SQL query to report the type of each node in the tree.

Sample Input:  Table_A                Output data: Table_B

ID

Parent_ID

 

 

Pat Id

Node_type

  

1

Null

 

 

1

Root

  

2

1

 

 

2

Inner

  

3

1

 

 

3

Leaf

  

4

2

 

 

4

Leaf

  

5

2

 

 

5

leaf

  

 

Type solution to Question here:

 

 

 

 

 

 

 

Question 4 

Below is the covid vaccination and tests details of patients.  Please write a query to calculate the percentage of total positive cases from the total number of tests conducted. The results should be stratified by their vaccination details.

Input table:

Pat Id

Test_date

Test_Result

Sex

Vaccination_1

Vaccination_2

1001

1-Jan-22

Positive

M

Y

N

1002

2-Jan-22

Positive

M

N

N

1003

3-Jan-22

Positive

M

Y

N

1004

4-Jan-22

Negative

F

Y

Y

1005

5-Jan-22

Negative

F

Y

Y

 

Output table

Vaccination details

Number of positive cases(n)

Number of test (N)

Percentage(n/N)

No vaccination

99

1000

0.099

Vaccination 1

20

100

0.2

Both vaccination

190

1111

0.17

 

Assume – Vaccination 2 can only be done after 1 and also for simplicity one patient can be tested only once.

Type solution to Question here:

 

1 REPLY 1
LinusH
Tourmaline | Level 20

1. These are different queries. You should put them in separate posts.

2. What have you tried so far?

Data never sleeps

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 473 views
  • 0 likes
  • 2 in conversation