BookmarkSubscribeRSS Feed
chennupriya
Quartz | Level 8

I Have two variables x and y

x has a format - NEGPAREN15.2

informat - comma 15.

length 8

y variable has format  - best12.

Informat - best12.

length -8

both are numeric variables

how to add both of them

i want z  variable which is sum of x and y

hhow to do in proc SQL and what format I need to assign to z variable

X Has values like (1,914,456.67)

Y has values like -106213.0235

2 REPLIES 2
CTorres
Quartz | Level 8

The format of a numeric variable is only a way to display the value in a report but it does not change anything in the variable so the way to code the sum is as simple as

select x+y as z in sql or z=x+y in a data step.

You can assign any format to z.

CTorres

ChrisHemedinger
Community Manager

The format of the variable -- used for appearance only in this case -- will not affect the math.  You will need to decide what you want the format of the calculated variable to be though.  Example that creates one calculation for each:

data test;
length x 8 y 8;
format x negparen15.2
       y
best12.;
x = -1914456.67;
y = -
106213.0235;
put x= y=;
run;

proc sql;
create table sum
as select x, y,
    (x+y)
as sum_negsign format=best12.,
    (x+y)
as sum_negparen format=negparen15.2
from test;
quit;

Chris
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1732 views
  • 0 likes
  • 3 in conversation