Help using Base SAS procedures

How to name decimal characters in SAS - Loop for data set

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 103
Accepted Solution

How to name decimal characters in SAS - Loop for data set

Good day SAS friends:

 

I need to know how to name this variable in the example, im working in categorical variables, so when the sample has no decimal characters, this means succes ("1") and when the characters have decimal characters means no succes ("0").

 

here is the data set and my programming (help me to fix it please):

 

data main;
input sample;
cards;
23

24

25

26.7

28

28.1

28.2

28.3
;
run;

data want;

set have;
z = .;

if sample = (number with no decimals)

then do;

z = 1;

result = "Succes!";
end;
else if x = (number with decimals) then do;

z = 0;

result = "No Succes";
end;
run;

proc print data=want;
var sample z result;
run;

 

Thank you very much

 


Accepted Solutions
Solution
‎12-07-2015 02:22 PM
Respected Advisor
Posts: 3,124

Re: How to name decimal characters in SAS - Loop for data set

[ Edited ]

If your data came in as numeric as you presented:

 

data main;
	input sample;
	cards;
 23
24
25
26.7
28
28.1
28.2
28.3
;
run;

data want;

set main;

length result $ 10;

z=sample=int(sample);

result=ifc(z=1,'success', 'no success');

run;

 

View solution in original post


All Replies
Super Contributor
Posts: 275

Re: How to name decimal characters in SAS - Loop for data set

data want;
   set main;
   z=0;
   result='No Succes';
   if index(sample,'.') then do;
     z = 1;
     result = "Succes!";
  end;
run;
Solution
‎12-07-2015 02:22 PM
Respected Advisor
Posts: 3,124

Re: How to name decimal characters in SAS - Loop for data set

[ Edited ]

If your data came in as numeric as you presented:

 

data main;
	input sample;
	cards;
 23
24
25
26.7
28
28.1
28.2
28.3
;
run;

data want;

set main;

length result $ 10;

z=sample=int(sample);

result=ifc(z=1,'success', 'no success');

run;

 

Frequent Contributor
Posts: 103

Re: How to name decimal characters in SAS - Loop for data set

Awesome

 

Thank a lot !!!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 465 views
  • 0 likes
  • 3 in conversation