DATA Step, Macro, Functions and more

proc sql - Creating lables

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

proc sql - Creating lables

i want to create labels for a dataset  using proc sql.

i used the code

proc sql; 
select PRODUCT_ID label="Line number" 
from a6.SMB;
quit;

but in the result the column name product_id is changed to line number.

In the original smb data-set the label has not been modified .

Why is it not working ?


Accepted Solutions
Solution
‎01-05-2018 03:58 PM
Super User
Posts: 13,046

Re: proc sql - Creating lables

Posted in reply to novinosrin

@novinosrin The OP's code did not create a table so there wasn't a table to assign a permanent label to the variable. It assigned a label to the variable in the output to the results window for a select.

 

proc sql;

   select sex label='Gender Label'

   from sashelp.class;

quit;

 

Won't change the label in sashelp.class which may be the OP intent. May, that's why I asked for clarification of intent.

View solution in original post


All Replies
Super User
Posts: 22,850

Re: proc sql - Creating lables

You didn't create a table, you only displayed results and they default to the Labels in presentation. 

 

If you want a data set, add a CREATE TABLE statement and then you can check the the variable name and label are different. If you'd like to apply a label to an already created data step and cannot back up to do so in another data step or proc sql, you can use PROC DATASETS to modify the library.

Super User
Posts: 13,046

Re: proc sql - Creating lables

By table do you mean a "report table" or "a newly created dataset for further use" or "an existing dataset"?

 

Your code created a report table in the results. It did not create a data set or modify an existing one.

 

Proc Datasets is the preferred way to modify existing data sets.

 

proc datasets library = a6;
   modify SMB;
     label Product_id = "Line Number";
quit;

There are options to suppress some of the information you'll get when running the procedure such as NODETAILS, NOLIST and/or NOPRINT on the procedure statement.

 

PROC Star
Posts: 1,328

Re: proc sql - Creating lables

[ Edited ]

Are you sure? My test has yielded the expected results

 

proc sql;
create table want as
select sex label="gender"
from sashelp.class;
quit;

 

proc contents;
run;

 

 

Proc contents -->SAS Output

Alphabetic List of Variables and Attributes# Variable Type Len Label1
SexChar1gender
Solution
‎01-05-2018 03:58 PM
Super User
Posts: 13,046

Re: proc sql - Creating lables

Posted in reply to novinosrin

@novinosrin The OP's code did not create a table so there wasn't a table to assign a permanent label to the variable. It assigned a label to the variable in the output to the results window for a select.

 

proc sql;

   select sex label='Gender Label'

   from sashelp.class;

quit;

 

Won't change the label in sashelp.class which may be the OP intent. May, that's why I asked for clarification of intent.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 142 views
  • 1 like
  • 4 in conversation