BookmarkSubscribeRSS Feed
acemanhattan
Quartz | Level 8

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.

4 REPLIES 4
SASKiwi
PROC Star

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

Reeza
Super User

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.

Ksharp
Super User

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

acemanhattan
Quartz | Level 8

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 994 views
  • 6 likes
  • 4 in conversation