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

Hi Iam running below code and iam getting error.please have a look and kindly help

 

proc sql;
   create table work.W5WITF2 as
      select
         
         (case 
            when Sign='C' 
            then input(Amt,11)/100
            when Sign='D' 
            then (input(Amt,11)/100)*-1
            else 
            end) as Amt length = 8
            format = 11.2
            informat = 11.2
            label = 'Amt',
         (case 
            when sign1='C' 
            then input(Amt1 ,11)/100
            when sign1='D' 
            then (input(Amt1 ,11)/100)*-1
            else
            end) as Amt1 length = 8
format = 11.2 informat = 11.2


label = 'Amt1', Sign, sign1 from test ; quit;


(case
595 when Sign='C'
596 then input(Amt,11)/100
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: a format name, ?.

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You need to end formats and informats with a dot for SAS to recognize it as such. Add a . (a dot) after 11 -> 11.

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

You need to end formats and informats with a dot for SAS to recognize it as such. Add a . (a dot) after 11 -> 11.

andreas_lds
Jade | Level 19

The second parameter of the input-function is a format-name and format-names end with . (dot), if they no decimals are specified.

JJP1
Pyrite | Level 9

Thanks @andreas_lds & @Patrick .

would you please confirm else is mandatory in CASe fumction?sorry to ask here

ballardw
Super User

@JJP1 wrote:

Thanks @andreas_lds & @Patrick .

would you please confirm else is mandatory in CASe fumction?sorry to ask here


Not at all mandatory:

proc sql;
  create table junk as
  select *,  case when age=13 then 'A' end as Something
  from Sashelp.class
  ;
quit;

If I only wanted to set the variable Something for the specific age of 13 and blank otherwise.

 

Good idea to include an Else? Likely so just so you document what was intended if nothing else.

If you were recoding an existing variable with the intent to leave other values as they already exist then you would need an ELSE. Otherwise then other values end up missing.

/* likely wrong approach*/
proc sql;
  create table junk as
  select name,sex,height,  case when age=13 then 26 end as Age
  from Sashelp.class
  ;
quit;

/* probably should be*/
proc sql;
  create table junk as
  select name,sex,height,  case when age=13 then 26 else age end as Age
  from Sashelp.class
  ;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 2488 views
  • 3 likes
  • 5 in conversation