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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1011 views
  • 0 likes
  • 3 in conversation