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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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

4 REPLIES 4
Reeza
Super User

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.

ballardw
Super User

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.

 

novinosrin
Tourmaline | Level 20

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
ballardw
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 26780 views
  • 3 likes
  • 4 in conversation