DATA Step, Macro, Functions and more

How to extract information from one Variable with several characteristics and use those information?

Reply
Highlighted
Contributor
Posts: 41

How to extract information from one Variable with several characteristics and use those information?

[ Edited ]

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 fromSmiley Happy 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

New Contributor
Posts: 4

Re: How to extract information from one Variable with several characteristics and use those informat

Posted in reply to marysmith

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.

Contributor
Posts: 41

Re: How to extract information from one Variable with several characteristics and use those informat

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...
New Contributor
Posts: 4

Re: How to extract information from one Variable with several characteristics and use those informat

Posted in reply to marysmith

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. 

 

Contributor
Posts: 41

Re: How to extract information from one Variable with several characteristics and use those informat

Thank you for your reply Smiley Happy

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 Smiley Happy
New Contributor
Posts: 4

Re: How to extract information from one Variable with several characteristics and use those informat

Posted in reply to marysmith

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.

Contributor
Posts: 41

Re: How to extract information from one Variable with several characteristics and use those informat

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

Super User
Super User
Posts: 9,386

Re: How to extract information from one Variable with several characteristics and use those informat

Posted in reply to marysmith

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.

Ask a Question
Discussion stats
  • 7 replies
  • 117 views
  • 0 likes
  • 3 in conversation