BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
glee217
Calcite | Level 5
/* This is the STATS301 start up file */
*Set up title on line 1;
TITLE1 "STATS 301 / 749750841 / glee217 : &sysuserid";
*Specify SAS library for storing permanent SAS datasets;
LIBNAME stats301 "C:\301";

***HERE
***import .sas7bdat file;
data temp;
set stats301.account_level_ds;
run;


data nonnegative;
set temp;
keep current_balance lending_interest;
if (current_balance <0) then delete;
rename lending_interest=yearint;
yearint = (current_balance)*0.03;
run;

title1 "nonnegative";
proc print data=nonnegative (obs=10);
run;

Hi I'm trying to create new variable called 'yearint' for data 'nonnegative' but somehow my code below doesn't work and it just gives me origianal 'lending_interest' value along to where it is not 'current_balance<0'

yearint = (current_balance)*0.03;

 how can i write down new variable and compute some new integer which is calculated with another variable?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You should ELSE IF instead of multiple IF and comment your code. It also seems weird to round one value and not the other for the same variable?

 

if (current_balance <0) then yearint = lending_interest;
else if (current_balance >=0) then yearint = int((current_balance)*0.03);

 


@glee217 wrote:
data integer;
set temp;

if (current_balance <0) then yearint = lending_interest;

if (current_balance >=0) then yearint = int((current_balance)*0.03);
run;

proc print data=integer (obs=10);
var current_balance yearint run;

hi sorry but can i ask you a difference question? i still want to create variable 'yearint' but this time i want to use 'current_balance' variable directly.  And it didn't give me decimal places. do you know how to fix this?

 캡처.JPG




View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your issue is likely the placement and use of rename - this is renaming another variable to be current balance.  This code below, renames the incoming variable, then your datasetp code will overwrite this.

Note some formatting changes:

title1 "STATS 301 / 749750841 / glee217 : &sysuserid";

libname stats301 "C:\301";

data nonnegative (keep=current_balance lending_interest);
  set stats301.account_level_ds (rename lending_interest=yearint);
  where current_balance < 0;
  yearint=(current_balance)*0.03;
run;

title1 "nonnegative";
proc print data=nonnegative (obs=10);
run;
glee217
Calcite | Level 5
data integer;
set temp;

if (current_balance <0) then yearint = lending_interest;

if (current_balance >=0) then yearint = int((current_balance)*0.03);
run;

proc print data=integer (obs=10);
var current_balance yearint run;

hi sorry but can i ask you a difference question? i still want to create variable 'yearint' but this time i want to use 'current_balance' variable directly.  And it didn't give me decimal places. do you know how to fix this?

 캡처.JPG

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You specify you want an integer result:

if (current_balance >=0) then yearint = int((current_balance)*0.03);

The int() is a function which returns only a hole number, remove that if you want decimals. 

Reeza
Super User

You should ELSE IF instead of multiple IF and comment your code. It also seems weird to round one value and not the other for the same variable?

 

if (current_balance <0) then yearint = lending_interest;
else if (current_balance >=0) then yearint = int((current_balance)*0.03);

 


@glee217 wrote:
data integer;
set temp;

if (current_balance <0) then yearint = lending_interest;

if (current_balance >=0) then yearint = int((current_balance)*0.03);
run;

proc print data=integer (obs=10);
var current_balance yearint run;

hi sorry but can i ask you a difference question? i still want to create variable 'yearint' but this time i want to use 'current_balance' variable directly.  And it didn't give me decimal places. do you know how to fix this?

 캡처.JPG




SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1383 views
  • 0 likes
  • 3 in conversation