Hello,
Using PROC SQL, I selected a column as, let's say, X. Now I want to use X as a variable later, in different procedures (e.g., PROC GLM). I tried to just use it but SAS doesn't recognize X as a variable. What should I do, so that SAS would recognize it as a variable?
Thank you in advance.
PROC SQL without a CREATE TABLE statement prints a data set it does not create any data so the variables are not available for use.If you want the variable available later you need to create a table with the data.
proc sql;
create table stepXXXX as
select
(N_mean + 10)/50 as LN,
(1 - N1_mean)*10 as LN1
from OUTSTAT_N;
quit;
proc corr data= stepXXXX plots = matrix(histogram);
var LN LN1;
run;
There are too many possibilities for anybody to guess at the solution. Show what you actually did, and it's likely that the solution is simple.
Here is an example of what I am trying to do. In general, what I am asking about is how do I use columns in PROC SQL later in different procedures? I need to specify "data = " in later PROC statements (e.g., proc corr in this example). But it's not data in proc sql, it's just a table...
data MC (keep = N N1 sampleID);
call streaminit(12345678);
do sampleID = 1 to 1000;
do i = 1 to 10;
N1 = rand('Normal');
N2 = N1*5 + 15;
N = floor(N2);
output;
end;
end;
run;
proc means data = MC;
by sampleID;
var N N1;
output out = OUTSTAT_N mean = N_mean N1_mean;
run;
proc sql;
select
(N_mean + 10)/50 as LN,
(1 - N1_mean)*10 as LN1
from OUTSTAT_N;
quit;
proc corr data= ??? plots = matrix(histogram);
var LN LN1;
run;
PROC SQL without a CREATE TABLE statement prints a data set it does not create any data so the variables are not available for use.If you want the variable available later you need to create a table with the data.
proc sql;
create table stepXXXX as
select
(N_mean + 10)/50 as LN,
(1 - N1_mean)*10 as LN1
from OUTSTAT_N;
quit;
proc corr data= stepXXXX plots = matrix(histogram);
var LN LN1;
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 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.