BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amanda_Lemon
Quartz | Level 8

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

Amanda_Lemon
Quartz | Level 8

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;
Reeza
Super User

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;
Amanda_Lemon
Quartz | Level 8
That was easy -- thank you!
LinusH
Tourmaline | Level 20
CREATE TABLE?
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 876 views
  • 0 likes
  • 4 in conversation