BookmarkSubscribeRSS Feed
marysmith
Calcite | Level 5

Help!

Dear SAS Community,

 

I really need your help, as I dont know how to do this - again!

I have data about a medicinal study which are included in different reports. There are different types of reports and they are all in the  Variable "Art_der_Anzeige" (=type of report) which has 4 characteristics: 1. Beendigung (=last final report), 2. Abschlussbericht (=final report) 3. Änderungsanzeige (change report) and 4. Erstanzeige (=first report). What I have to do, is to use the information from the last final report, but if there is no final report yet, I have to use the information from final report. If the study is not completed yet I habe to use information from change report and if even thats not published I have to use the data from the first report. How to do this???

 

I tried something like that, but of course it didnt work

 

data saspms.datensatz_pms_Anzeige;
set saspms.datensatz_pms_awb;
Anzeige = input (Art_der_Anzeige);
if Beendigung = 1 then (use information from:) Anzeige = Beendigung;
if Beendigung = 0 and Abschlussbericht= 1 then Anzeige =Abschlussbericht;
if Beendigung = 0 and Abschlussbericht = 0 then Anzeige = Änderungsbericht;
if Beendigung = 0 and Abschlussbericht = 0 and Änderungsbericht = 0 then Anzeige= Erstanzeige;

run;

 

 


rawb.PNG

7 REPLIES 7
ashkar
Fluorite | Level 6

Hi,

 

Not sure if I understood your question completely.

Do you want to read a particular record in your saspms.datensatz_pms_awb dataset based on the hierarchy you have mentioned for a group?

 

In that case, try setting a flag value to each category(1,2,3,4 based on the hierarchy) within a group and sort the records based on this flag value.

And pick the very first record in your group using if first.

marysmith
Calcite | Level 5
Hello thank you for your reply:
What I need to do is to use the information from the last final report if existing. If not, I need SAS to use the information from the final report. If there is no last final report and no final report sas should use the information from change report and if there is no last final report, final report and no change report, in this case I need to take the information from the first report...
ashkar
Fluorite | Level 6

When you say use the information from a particular report, all that information is lying your saspms.datensatz_pms_awb dataset , right?

And for what group are you checking if the data exists in a particular report or not? In cant be on the whole set of data. 

 

marysmith
Calcite | Level 5
Thank you for your reply 🙂

1. Yes, exactly it is, all that information is lying in saspms.datensatz_pms_awb

2. Like for example I need to know how many patients were in this study. And that's variates from report to report. At the beginning they are planning to interview 1000 patients , but sometimes the last final report contains only 500 patients. So I always need the information from the last final report, but some of the studies are ongoing and not finished yet, so I need to use the information from the first report or change report..
Thank you so much 🙂
ashkar
Fluorite | Level 6

Ok I assume this is how your data might look like :

 

Here "Group" is what differentiates one study from the other. It should be your primary key in your source dataset. 

 

Group         Report_Type                 No_Of_patients

Study1       Beendigung                   500

Study1       Abschlussbericht           500

Study1       Änderungsanzeige        750

Study1       Erstanzeige                   1000  

Study2       Änderungsanzeige        200

Study2       Erstanzeige                   350

Study3       Erstanzeige                   400

 

In this case, the first study has all the 4 categories, while the 2nd study is only at change report level as it is still ongoing and the 3rd study has just begun.

 

data toto;

set saspms.datensatz_pms_awb;

If Report_Type = "Beendigung" then Hierarchy = 1;

Else if Report_Type = "Abschlussbericht " then Hierarchy = 2;

Else if Report_Type = "Änderungsanzeige" then Hierarchy = 3;

Else Hierarchy = 4;

run;

 

/* now every record will have a flag value set from 1 to 4 based on the hierarchy of fetching information from reports*/

/* Sort this information so that the first record for each group will always have the record which must be picked*/

proc sort data = toto;

by Group Hierarchy;

run;

 

/* Pick the first record for each group*/

data saspms.datensatz_pms_Anzeige;

set toto;

If first.Group;

run;

 

 

Now, I have made a couple of assumptions in this solution.

Let me know if it works or is your data looking different to what i have assumed.

Please share sample data if possible if the above doesn't work.

 

Thanks.

marysmith
Calcite | Level 5

Thank you for your reply. I will let you know if it worked out for me! Thank you 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, you need to supply some clear cut cases for us to understand.  You seem to be mixing up outputs and data.  What is it you have, and what is it you want.  E.g.

I have two sets of possible data

1) Final data called final in libname final

2) Final data in report, called final in libname finalrep

 

My program needs to work off 2) if present, and 1) if not.  Therefore:

%macro SetLib;

  %if exist(finalrep.final) %then %do;
libname mydata ".../final";
%end;
%else %do;
libname mydata ".../finalrep";
%end;
%mend SetLib;

/* Now here is my general code based on that data */
data want;
set mydata.final;
run;

In this way we choose to set our libname to one or the other data and all further code uses that one libname.

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
  • 1072 views
  • 0 likes
  • 3 in conversation