Wednesday - last edited Wednesday
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
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;
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.
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.
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.
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;
/* 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;
/* Pick the first record for each group*/
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.
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";
libname mydata ".../finalrep";
/* Now here is my general code based on that data */
In this way we choose to set our libname to one or the other data and all further code uses that one libname.