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

I've created a table on proc sql then tried to access it and adjust it through sas. it keeps giving me an empty output

I've used the following code:


proc sql;
create table mylib.test as
select *
from lib1.data1
where var2='202220'
order by var3, var4;

quit;

data temp.test;
rename var1=ID;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You have no SET statement. 

A SET statement tells SAS what the input data set is. Since there is none,  there is no data to work with in that step. 

 

The data step actually deletes your initial step and replaces that data with nothing. 

 

This is probably what you want but not a good idea. Whenever you have a data step its not a good idea to have your SET and DATA reference the same data set. This destroys your original data set so if you make a mistake you have to go back extra steps. 

data mylib.test;
set mylib.test;

rename var1 = ID;
run;

Instead you can build on it:

 

data mylib.test2;
set mylib.test;

rename var1 = ID;
run;

Or use PROC DATASETS to rename the variable. This is actually the fastest, most efficient option as it just changes the metadata/variable name. In a Data step or SQL proc it actually go through all the data and recreates a new data set at the end. 

 

proc datasets lib=mylib;
modify test;
rename var1=id;
run;quit;

 


@Abdulla1 wrote:

Thanks that works very well.

however, I'm trying to change the variable var1 into ID can I do that without setting new variable

I tried the code below but it didn't work either.

 

proc sql;
create table mylib.test as
select *
from lib1.data1
where var2='202220'
order by var3, var4;

quit;

data mylib.test;
rename var1=ID;
run;


 

View solution in original post

4 REPLIES 4
Reeza
Super User

The code is correct, syntax wise, but logically incorrect. 

 

What are you trying to do?

 

The last data step will not do anything for example. 

The code snippets don't seem to align, you create a table in mylib but then try and reference a data set in temp with the same name? However no input data set is provided. 

I can only offer a very broad suggestion to fix it because I don't know what you're trying to accomplish. 

 

data test;
set mylib.test;

rename var1 = ID;
run;
Abdulla1
Quartz | Level 8

Thanks that works very well.

however, I'm trying to change the variable var1 into ID can I do that without setting new variable

I tried the code below but it didn't work either.

 

proc sql;
create table mylib.test as
select *
from lib1.data1
where var2='202220'
order by var3, var4;

quit;

data mylib.test;
rename var1=ID;
run;

Reeza
Super User

You have no SET statement. 

A SET statement tells SAS what the input data set is. Since there is none,  there is no data to work with in that step. 

 

The data step actually deletes your initial step and replaces that data with nothing. 

 

This is probably what you want but not a good idea. Whenever you have a data step its not a good idea to have your SET and DATA reference the same data set. This destroys your original data set so if you make a mistake you have to go back extra steps. 

data mylib.test;
set mylib.test;

rename var1 = ID;
run;

Instead you can build on it:

 

data mylib.test2;
set mylib.test;

rename var1 = ID;
run;

Or use PROC DATASETS to rename the variable. This is actually the fastest, most efficient option as it just changes the metadata/variable name. In a Data step or SQL proc it actually go through all the data and recreates a new data set at the end. 

 

proc datasets lib=mylib;
modify test;
rename var1=id;
run;quit;

 


@Abdulla1 wrote:

Thanks that works very well.

however, I'm trying to change the variable var1 into ID can I do that without setting new variable

I tried the code below but it didn't work either.

 

proc sql;
create table mylib.test as
select *
from lib1.data1
where var2='202220'
order by var3, var4;

quit;

data mylib.test;
rename var1=ID;
run;


 

Abdulla1
Quartz | Level 8

thank you @Reeza 

that is very helpful.

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 607 views
  • 2 likes
  • 2 in conversation