BookmarkSubscribeRSS Feed
deleted_user
Not applicable
i have a dataset

data x;
input id tot;
cards;
5 1
6 2
7 .
5 1
6 2
9 .

Now i want a new variable i want the sum of id having 1 and 2
2 REPLIES 2
Andre
Obsidian | Level 7
This kind of problem looks like homework.

Here is thus an answer but you have to read documentation
about the "retain" statement to understand the first step which is calculating your results

http://support.sas.com/onlinedoc/913/getDoc/fr/lrdict.hlp/a000214163.htm

the second datastep is showing you that the result are in the table on the last observation
but understanding this step is not trivial and need a 'sum' of practice.

Andre

[pre]
data x;
infile cards ;
input id tot; retain one two 0;
if tot=1 then one+id;
if tot=2 then two+id;
cards;
5 1
6 2
7 .
5 1
6 2
9 .
run;
data _null_;
set x nobs=l point=l;
put one= two= ;
stop;
run;
[/pre]
deleted_user
Not applicable
PROC SQL;
create table y as
select sum(id) as sum_id
from x
where tot =1 or tot = 2;
QUIT;

OR

PROC SQL;
create table y as
select sum(id) as sum_id, tot
from x
where tot =1 or tot = 2
group by tot;
QUIT;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 618 views
  • 0 likes
  • 2 in conversation