BookmarkSubscribeRSS Feed
Joyful3
Calcite | Level 5

hi everyone,

I need to create a dataset for EACH of the 20 patients using MACRO.

 

The dataset shown below have 20 patient names and 3 variables - their  income, average number of visits to doctors in last 3 months and average healthcare spending.

 

Name  income visit  Spend  

Alex     100  10.45        10.20      

Bruce   200  2.51          50.21    

Candy  150   5.21        15.21       

etc...

i tried the following but it is not creating any dataset at all

data serial;
set patient;

call symput('Name', Name);
call symput('Income', Income);
call symput('Visit', Visit);
call symput('Spend', Spend);

call symputx('numnames',_n_);

 

%patient(&Name, &Income, &Visit, &Spend,&Count);


Run;

 

please advice

.

 

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Do each patient have several observations in your data?

RichardDeVen
Barite | Level 11

Want do you want to do with the data you have ?  

Is the data one row per patient name?

 

You probably don't need to separate the data by name into different data sets because the data you already have appears to be one row of aggregate results (income, mean visits (maybe should be count?) and mean spending (per visit?)), for each patient.

 

You might be well served with a BY statement somewhere in your downstream processing if you join your aggregates with other detail data.

ballardw
Super User

Here is one of the ways to "split" data that way.

 

Note, no macro needed at this stage though writing 20 outputs like this does take a small amount of time:

data patient;
   input Name $ income visit  Spend  ;
datalines;
Alex     100  10.45        10.20      
Bruce   200  2.51          50.21    
Candy  150   5.21        15.21    
;

data Alex
     Bruce
     Candy
;
   set patient;
   select (name);
      when ("Alex") output Alex;
      when ("Bruce") output Bruce;
      when ("Candy") output Candy;
      otherwise ;
   end;
run;

But really, how do you intend to use those 20 data sets?

If you want to do analysis on a subset of the data you can use WHERE to restrict it to specific names:

proc means data=patient;
   where name in ('Alex' 'Candy');
   var income spend;
run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 466 views
  • 1 like
  • 5 in conversation