Hi,please how to construct a histogram for a set of means say X1-X1000 that Ihave calculated?
I did the following:
proc univariate data=pop;
var mn_X1-mn_X1000;
histogram;
run;
where mn_x means the mean of x1
but they gave me many histograms fo each mean but I need only one histogram for all the means.
thanks a lot
Transpose your data so that you have a two variables
VariableNum Mean
1 25
2 34
3 45
4 34
...
1000 45
And then run proc univariate on the mean variable.
You can look into proc transpose to flip the data.
sorry but it doesnt work
how?
PGStats used nm_x as a prefix for the variable names, rather than mn_x. If you change the code to use mn_x as a prefix, the code works perfectly. The code below demonstrates that with three means.
data pop;
input mn_x1 mn_x2 mn_x3;
datalines;
1 5 7
;
run;
data popList;
length id $12;
set pop;
array mn{*} mn_x:;
do i = 1 to dim(mn);
x = mn{i};
id = catx("_", _n_, i);
output;
end;
keep id x;
run;
proc univariate data=popList;
var x;
id id;
histogram;
run;
I put the means in a table as follows
data histo;
set proc_means;
array x{*}nm_x1-nm_x1000;
run;
now Iwant to put that table in a variable say F but I didnt find a solution I did the following but it doesnt work
data histo;
set proc_means;
array x{*}nm_x1-nm_x1000;
s=x{nm_x1-nm_x1000};
run;
could you please help me
I put the means in a table as follows
data histo;
set proc_means;
array x{*}nm_x1-nm_x1000;
run;
now Iwant to put that table in a variable say S but I didnt find a solution I did the following but it doesnt work
data histo;
set proc_means;
array x{*}nm_x1-nm_x1000;
s=x{nm_x1-nm_x1000};
run;
could you please help me
The easiest way to do that is to use the TRANSPOSE procedure. After you transpose the data, you'll need to drop the _name_ variable and rename the col1 variable to s. The code below shows how to do this.
data proc_means;
input mn_x1 mn_x2 mn_x3;
datalines;
1 5 7
;
run;
proc transpose data=proc_means out=histo;
var mn:;
run;
data histo;
set histo (drop=_NAME_ rename=col1=s);
run;
Your code is missing the do loop portion from PG's code.
If you open the data set does it look like the structure I've recommended in my post?
The do loop is not necessary after using the TRANSPOSE procedure. The data set would appear as follows:
S
1
5
7
If you want to keep the variable label for each observation, just remove "drop=_name_" from the code I previously posted and the result is as follows.
The _name_ variable is not necessary for generating the histogram, but you can keep it if you like. The code for generating the histogram is:
proc univariate data=histo;
var s;
histogram;
run;
I was trying to explain why the code used did not work, it was not a full implementation of the suggested code.
The code suggested by PG should work as well, just a different way to transpose.
I misunderstood. You are correct that the code suggested by PG would also work, as long as the variable names are changed to be the same as those used by mesdz (e.g., mn_x1, not nm_x1).
you meant that I have to replace nm_x1 by mn_x1?
Yes, exactly. Or you can just copy the code that I posted previously.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.