Proc sql select * statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc sql select * statement

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


Accepted Solutions
Solution
‎01-12-2017 12:51 PM
PROC Star
Posts: 7,363

Re: Proc sql select * statement

[ Edited ]

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

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,395

Re: Proc sql select * statement

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

Solution
‎01-12-2017 12:51 PM
PROC Star
Posts: 7,363

Re: Proc sql select * statement

[ Edited ]

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

 

Occasional Contributor
Posts: 15

Re: Proc sql select * statement

Thanks......
Valued Guide
Posts: 505

Re: Proc sql select * statement

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;


Occasional Contributor
Posts: 15

Re: Proc sql select * statement

Thanks Roger.... this is what I was looking for.
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 374 views
  • 2 likes
  • 4 in conversation