Reply
Thu 3 Feb, 2005 11:35 pm
I am a newbie in using SAS. Actually I am studying it. I have got a question for 2 days and I don't know how to solve it.
Problem:
I created a dataset file named "abcd.sas7bdat" which contains about 5 numeric variables (ie: a, b, c, d, e). What I want is that I would like to take 2 variables and the subtract them together and assign to a new variable (eg: x = a - c).
I started SAS program and then use " infile " statement to call it, then
=======================
DATA temp;
INFILE 'C:\SAS\abcd.sas7bdat';
INPUT a c;
x = a - c;
RUN;
=======================
There are a lot error in reading this code. WOuld you please show me how to get what I really want.......
Thank you so much for your help,
Terry Vu
SAS being Side-Angle-Side congruence theorem or am I just completely confused?
No Software
SAS is a statistical software package. I haven't written SAS in at least five years. What is the error you are getting? If the INPUT statement fails, all of the others will also.
problem explanation
Thank you so much for your replies.
What I really want to do is: Read a file which contains data and do a very simple mathematic calculation ie: subtraction.
What I did:
1. After working around with SAS, I can read a file now (ie: sample.dat, sample.txt but not sample.sas7bdat) by INFILE statement and then do mathematic / statistic calculation.
However, IF data stored in " sample.dat " having " TAB " then there will be error saying SAS cannot read and CHAR ......xyz.......NUM...... . This problem could be fixed by changing a TAB by series of space using space bar.
My question for this problem is: IF data stored in sample.dat having TABs, how can we read the data?
=======ooo00ooo========
2. About sample.sas7bdat file. I still cannot read this kind of SAS file once it has been created using INFILE statement and do mathematic work with it.
My question for this problem is: How to read file which ends up with "sas7bdat" ie: sample.sas7bdat ?
I greatly appreciate your help. Hope to have your answer soon.
Have a nice day,
Terry Vu
SAS Help
1. To read sample.dat containing TAB characters, just add EXPANDTABS to the INFILE statement
ie INFILE 'C:\SAS\sample.dat' EXPANDTABS;
2. You have already created a permanent SAS dataset called abcd so you don't need to read it in again. If you look in C:\SAS you will find it called abcd.sas7bdat
So if you want to add a new variable, you just have to make sure you have a LIBNAME pointing to the directory then create a new dataset or overwrite the first one, eg
LIBNAME L 'C:\SAS';
DATA L.ABCD;
SET L.ABCD;
X=A-C;
RUN;
wow....It is so clear Ex_Pat. I got it now. Thank you so much for your help.
Have a nice day,
Terry Vu