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
.
Do each patient have several observations in your data?
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.
NO SAS processing I can think of requires you to split such a minuscule dataset.
So my advice is very simple: don't.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: