Desktop productivity for business analysts and programmers

DATA Step adding variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 112
Accepted Solution

DATA Step adding variables

Hi All,

 

I am using the IF statements to allocate numbers to variables, then I need to create a new variable that shows the total of these.

But when I use I create the new variable in another data step it doesn't add them together.

 

 

IF Active_INAa > ' ' THEN
		INAa = 1;

	IF Active_INDa  > ' '  THEN
		INDa = 2;

	IF Active_IRSa  > ' '  THEN
		IRSa = 4;

	IF Active_INIa  > ' '  THEN
		INIa = 8;

 

 

 

 

Data work.Test2;
	SET work.Test1;
	Total = INAa + INDa + IRSa + INIa;
RUN;

 

The Total column is created but is blank.

 

What am I missing here? Any help appreciated.

 

Cheers

 

Dean

 

 

 

 

 


Accepted Solutions
Solution
3 weeks ago
PROC Star
Posts: 1,603

Re: DATA Step adding variables

missing+value=missing

 

so try

 

total=sum(INAa ,INDa , IRSa, INIa);  

 

View solution in original post


All Replies
Solution
3 weeks ago
PROC Star
Posts: 1,603

Re: DATA Step adding variables

missing+value=missing

 

so try

 

total=sum(INAa ,INDa , IRSa, INIa);  

 

Frequent Contributor
Posts: 112

Re: DATA Step adding variables

Posted in reply to novinosrin

Thanks @novinosrin

 

Works now.

 

Cheers

 

Dean

Super User
Posts: 3,866

Re: DATA Step adding variables

[ Edited ]

Try  a SUM statement if you want to add them up across your whole dataset:

 

Data work.Test2;
	SET work.Test1;
	Total + INAa + INDa + IRSa + INIa;
RUN;

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 104 views
  • 2 likes
  • 3 in conversation