Hi everybody,
Is there any way / options to view the output of the select * query to display column name instead of column label in the result tab (SAS University Edition)
for eg select * from sashelp.cars
it will return the result with the heading as
Make, Model, Type, Origin, DriveTrain, MSRP ,Invoice, Engine Size (L), Cylinders, Horsepower, MPG (City), MPG (Highway), Weight (LBS), Wheelbase (IN), Length (IN)
Instead what I am looking is something as below
Make, Model, Type, Origin, DriveTrain, MSRP, Invoice, EngineSize, Cylinders, Horsepower, MPG_City, MPG_Highway, Weight, Wheelbase, Length
Thanks,
a_k93
While there may be an option for that, I'm not familiar with it. However, here is a way to get around that functionality:
proc sql noprint;
select catx(' ',name,"label=' '")
into :labels separated by ", "
from dictionary.columns
where libname='SASHELP' and
memname="CARS"
;
quit;
proc sql;
select &labels.
from sashelp.cars
;
quit;
Note: While the above does what the OP asked about, Roger's solution (later in this thread .. using option nolabel) is a better solution.
HTH,
Art, CEO, AnalystFinder.com
Using SAS UE, while you are browsing a dataset, either in OUTPUT DATA or directly in SASHELP.anydata
there is a "view" that enables chose "Column names" or "Column labels".
While there may be an option for that, I'm not familiar with it. However, here is a way to get around that functionality:
proc sql noprint;
select catx(' ',name,"label=' '")
into :labels separated by ", "
from dictionary.columns
where libname='SASHELP' and
memname="CARS"
;
quit;
proc sql;
select &labels.
from sashelp.cars
;
quit;
Note: While the above does what the OP asked about, Roger's solution (later in this thread .. using option nolabel) is a better solution.
HTH,
Art, CEO, AnalystFinder.com
Options
label and nolabel turns labesl off and on
data class;
label
age="Age hs a label"
;
set sashelp.class(keep=name age);
run;quit;
proc sql;
select
*
from
class
;quit;
Age hs
a label NAME
------------------
14 Alfred
13 Alice
13 Barbara
14 Carol
14 Henry
options nolabel;
proc sql;
select
*
from
class
;quit;
AGE NAME
------------------
14 Alfred
13 Alice
13 Barbara
14 Carol
14 Henry
12 James
12 Jane
options label;
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.
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.