Solved
Contributor
Posts: 39

# Doing mathematical operations with proc sql insert into values()

[ Edited ]

Hello all,

is it possible to use mathematical operations in the values() statement? For example

data have;
input x \$ y z;
datalines;
a 1 2
b 3 4
;

proc sql;

insert into have values('c',5,6);
insert into have values('d',3*1,7-6);
quit;

The first insert statement works but the second does not. Is it possible to use mathematical operations?

Accepted Solutions
Solution
‎12-20-2016 03:28 PM
PROC Star
Posts: 631

## Re: proc sql insert into values() question

data have;

input x \$ y z;

datalines;

a 1 2

b 3 4

;

proc sql;

insert into have values('c',5,6);

insert into have values('d',%EVAL(3*1),%EVAL(7-6));

quit;

Thanks,
Suryakiran

All Replies
Solution
‎12-20-2016 03:28 PM
PROC Star
Posts: 631

## Re: proc sql insert into values() question

data have;

input x \$ y z;

datalines;

a 1 2

b 3 4

;

proc sql;

insert into have values('c',5,6);

insert into have values('d',%EVAL(3*1),%EVAL(7-6));

quit;

Thanks,
Suryakiran
Contributor
Posts: 39

## Re: proc sql insert into values() question

Posted in reply to SuryaKiran

Thank you for your response! A followup question: how would I use the %EVAL function with date literals.

For example how can I do

insert into have values('d',%EVAL(3*1),%EVAL('29DEC2015'd-'28DEC2015'd));

Super User
Posts: 13,942

## Re: proc sql insert into values() question

[ Edited ]

No reason to use %eval just use ('29DEC2015'd-'28DEC2015'd)

Though learning th INTCK function will help in the future.

Contributor
Posts: 39

## Re: proc sql insert into values() question

[ Edited ]

When I tried using just the literals I got an error but using %sysevalf worked. I guess date literals are considered floating point values and not purely interger values

insert into have values('d',%eval(3*1),%sysevalf('29DEC2015'd-'28DEC2015'd));

PROC Star
Posts: 631

## Re: proc sql insert into values() question

proc sql;

insert into have values('c',5,6);

insert into have values('d',%EVAL(3*1),%SYSFUNC(INTCK(DAYS,'28DEC2015'd,'29DEC2015'd)));

quit;

Thanks,
Suryakiran
☑ This topic is solved.

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

Discussion stats
• 5 replies
• 351 views
• 0 likes
• 3 in conversation