BookmarkSubscribeRSS Feed
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       


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);



please advice





Tourmaline | Level 20

Do each patient have several observations in your data?

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.

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  ;
Alex     100  10.45        10.20      
Bruce   200  2.51          50.21    
Candy  150   5.21        15.21    

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

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;



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