would you please show me how to use "indsname" given the sample dataset I have provided? Thanks
I do not know how to list variables there, so please provide sas sample code
INDSNAME does not list variables, it creates a variable that shows where a row came from. You're also mixing solutions, if you want a macro you don't need INDSNAME, follow the steps I outlined. If you want a single proc then you would use the INDSNAME option.
*Generate sample data;
data class;
set sashelp.class(obs=5);
run;
data class2;
set sashelp.class(obs=13 firstobs=9);
run;
/*Sample using INDSNAME*/
data example;
set class class2 indsname=source;
data_source = source;
run;
proc print data=example;
run;
OUTPUT:
Obs Name Sex Age Height Weight data_source
1 Alfred M 14 69.0 112.5 WORK.CLASS
2 Alice F 13 56.5 84.0 WORK.CLASS
3 Barbara F 13 65.3 98.0 WORK.CLASS
4 Carol F 14 62.8 102.5 WORK.CLASS
5 Henry M 14 63.5 102.5 WORK.CLASS
6 Jeffrey M 13 62.5 84.0 WORK.CLASS2
7 John M 12 59.0 99.5 WORK.CLASS2
8 Joyce F 11 51.3 50.5 WORK.CLASS2
9 Judy F 14 64.3 90.0 WORK.CLASS2
10 Louise F 12 56.3 77.0 WORK.CLASS2
Thanks. I still do not get where "source", from your code below, is from, and how I should replace it. I understand there are two options, one is macro code, that I will be working on, and this solution as well.
I do not know what 'source' means in your code, this is why I provided my sample dataset.
I do not understand how to use "indsname" and I do not know where 'source' is from. that is hard for me to learn. Would you please give me a sas code, based on my sample dataset, so that I can understand how to use "indsname"
indsname
Thank you. Would you please provide sample code? That will be very helpful. It is hard for me to understand.
Wrap your code in %macro/%mend and assign a name, eg:
%macro summarize;
*your sas code;
%mend;
%summarize;
%macro summarize(dataset);
proc means data=&dataset;
...
run;
%summarize(bpchild);
this is my code, based on your code above
I am thinking to have a variable that can be used to replace child, adult, senior and over100. There are some problems with this code, so please give advice. thanks
%macro sum;
proc sort data=bp2∑
by patientid;
run;
PROC means DATA=bp2∑
var wvr_:;
run;
%mend;
data want;
set bp2∑
run;
%sum(child, adult, senior, over100)
So from the test data you posted:
data childhave;
input patientid var_hed var_eye var_col var_leg var_hea var_lea var_alh;
You proc means is simply:
proc means data=childhave; var var_:;
run;
that is right
but in order to avoid to replace my dataset repeatedly, i am asking for advice to have a sas macro, so that I need not do it repeatedly
also, i am asking for advice whether there is a sas code to compare the frequency of each variable afterwards
Sorry, why do you need to replace your dataset repeatedly? You posted some test data, I posted a proc means, which creates one proc means output for the data you provided. Where oes this repetition come into it?
That is my question. I have four simiar datasets. I need to generate four tables, regarding the frequency order of these variables. I provided one sample dataset. My question is how to use macro so that i need not replace them repeatedly.
please see my original post below
I have four datasets, child, adult, senior and over100, each one has over 10000 obs.
the orginal code is very simple
proc sort data=bpchild;
by id;
run;
PROC means DATA= bpchild;
var wvr_:;
run;
proc contents data= bpchild;
run;
I just need to replace child with adult, senior, over100.
would anybody teach me how to use macro do this?
Post your question about comparing freq as a new thread please, this one is confusing enough as it is.
So back to the code posted on the first page:
/* Put the four datasets together and create a variable which idenfies which dataset each observation came from */ data all; set child adult senior over100 indsname=source; dsetname=source; run; proc sort data=all; by dsetname id; run; /* Run a proc means on this one dataset, do it by dateset the original observation came from to split the results on dataset */ proc means data=all; by dsetname; var var_:; output out=want n=n mean=mean...; run;
/* Run a proc freq on this one dataset, do it by dataset the original observation came from */
proc freq data=all;
by dsetname;
...
run;
Thank you. Can you explain your last part?
/* Run a proc freq on this one dataset, do it by dataset the original observation came from */
proc freq data=all;
by dsetname;
...
run;
I do not know what to add, I add "patientid" or not add, sas is busy.
what do you mean by
do it by dataset the original observation came from
Thank you.
I did run your code. The problem is, I could not generate these four tables that I expect.
what should I do with the dataset "want"? I need to count the frequencies of those variables.
var_hed var_eye var_col var_leg var_hea var_lea var_alh
would you plesae explain a little more about your code below regarding those frequencies variables that I need to count and I need to list them according to order of the frequencies.
proc means data=all; by dsetname; var var_:; output out=want n=n mean=mean...; run;
/* Run a proc freq on this one dataset, do it by dataset the original observation came from */
proc freq data=all;
by dsetname;
...
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.