BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
proc sql;
select * case when sex='F' then  'Female'
else   'Male'  end as newvar from sashelp.class;
quit;
6 REPLIES 6
Amir
PROC Star

Well, the OP has already posted a query...

tarheel13
Rhodochrosite | Level 12

You need to put a comma after the *. 

jimbarbour
Meteorite | Level 14

It just needs a comma after the asterisk.  Like this:

     proc sql;
         select *, case when sex='F' then  'Female'
         else   'Male'  end as newvar from sashelp.class;
     quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0:00:00.04
      cpu time            0:00:00.03
      Timestamp           June 25, 2021 10:22:46

@tarheel13 is quite correct in his assessment.

 

Jim

ballardw
Super User

@BrahmanandaRao wrote:
proc sql;
select * case when sex='F' then  'Female'
else   'Male'  end as newvar from sashelp.class;
quit;

You did read the log that clearly points out the error didn't you?

215  proc sql;
216  select * case when sex='F' then  'Female'
              ----
              22
              76
ERROR 22-322: Syntax error, expecting one of the following: ',', FROM, INTO.

ERROR 76-322: Syntax error, statement will be ignored.

217  else   'Male'  end as newvar from sashelp.class;
218  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

The underscores under CASE show where the problem is and the error text says you are missing something like a comma.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1338 views
  • 0 likes
  • 6 in conversation