DATA Step, Macro, Functions and more

Code Unintentionally Causes Data to be Omitted. How to Fix?

Reply
Contributor
Posts: 30

Code Unintentionally Causes Data to be Omitted. How to Fix?

I have this dataset:

Provider                                             Referred To                                             Percent

104TH AVENUE MEDICAL CLINICVALLEY MEDICAL CENTER RENTON0.16827527321
104TH AVENUE MEDICAL CLINICFEDERAL WAY MEDICAL INVESTOR0.13099054442
104TH AVENUE MEDICAL CLINIC104TH AVENUE MEDICAL CLINIC0.08628050363
2BWELLMARK YERBY0.34504089631
2BWELLNORTHWEST ENDOCRINOLOGY LLC0.25037230512
2BWELLJAY PAUL DOUGLASS MD LLC0.21520379413
4TH STREET MEDICAL CAREPROVIDENCE EVERETT0.60619607991
4TH STREET MEDICAL CAREWESTERN WASHINGTON MED GROUP0.11327938362
4TH STREET MEDICAL CARE4TH STREET MEDICAL CARE0.05712185553

This code produces the following dataset


DATA data.top_3;

  SET data.top_3_allwd; BY attributed_tin_nm_rllp;

  * Tells SAS not to reset these variables to

  missing when going to top of datastep;

  RETAIN first second third percent1 percent2 percent3;

  * Set variables to missing when reading new

  member - clear previous member's data!;

  if FIRST.attributed_tin_nm_rllp = 1 then do;

  first=.; second=.; third=.;

  percent1=.; percent2=.; percent3=.;

  end;

  if count = 1 then do ;

  first = prov_name_serv; percent1= percent_of_allwd;

  end;

  if count = 2 then do ;

  second = prov_name_serv; percent2= percent_of_allwd;

  end;

  if count = 3 then do ;

  third = prov_name_serv; percent3= percent_of_allwd;

  end;

  * Output variables only when done with member;

  if LAST.attributed_tin_nm_rllp = 1 then OUTPUT;

  KEEP attributed_tin_nm_rllp first second third percent1 percent2 percent3;

RUN;

Provider                                             1st   2nd     3rd      1st %             2nd%              3rd%

104TH AVENUE MEDICAL CLINIC       .       .       .0.16827527320.13099054440.0862805036
2BWELL...0.34504089630.25037230510.2152037941
4TH STREET MEDICAL CARE...0.60619607990.11327938360.0571218555

The problem is that the name of the referred to clinics gets omitted, but I can't see why.

Super User
Posts: 3,102

Re: Code Unintentionally Causes Data to be Omitted. How to Fix?

Add the "Referred To" variable to your KEEP statement.

Super User
Posts: 17,784

Re: Code Unintentionally Causes Data to be Omitted. How to Fix?

Which Referred to variable are looking to keep, all three or the first/last?

Assuming you're trying to flip your data you should look into proc transpose or arrays:

SAS Learning Module: Reshaping data long to wide using the data step

I think has a macro that does multiple columns at once as well.

Super User
Posts: 9,671

Re: Code Unintentionally Causes Data to be Omitted. How to Fix?

You mean Arthur.T ? We don't see him for a long time at this forum. Want know where he is .

A Better Way to Flip (Transpose) a SAS Dataset - sasCommunity

Contributor
Posts: 30

Re: Code Unintentionally Causes Data to be Omitted. How to Fix?

The problem was with this part of the code:

if FIRST.attributed_tin_nm_rllp = 1 then do;

  first=.; second=.; third=.;

it was fixed when I changed to

if FIRST.attributed_tin_nm_rllp = 1 then do;

  first=' '; second=' '; third=' ';

and preceded this with

FORMAT first second third $CHAR105.;

Thanks for the responses.

Ask a Question
Discussion stats
  • 4 replies
  • 250 views
  • 6 likes
  • 4 in conversation