Hi kushiwije,
Can you provide a clearer example? How does your dataset look at the moment?
It would help us identify the crux of the problem if you can provide a brief illustration of how your data is, and how you want it to be.
Thanks
Hi STrookie,
The month function will return the integer month from a SAS date. So you can subset for dates not on the 9th month:
*display dates not in September(month 9) ;
if month(nipr_exp_dt1) ne 9 ;
Hi Tariq,
When creating the dataset you have the ability to password protect aspects of it. For example, you can set separate passwords for reading, writing and altering the dataset/view. Alternatively, you can use the pw keyword to assign a full lock on your dataset.
data...
...is that the datastep allows for combinations of different types of loops for more complex conditions.
Here is a rather contrived example
*Print all integers whose sum does not exceed 20 ;
data _null_ ;
do i = 1 to 10 while (tot < 20) ;
put i= tot= ;
tot ++ i ;
end ...
Hi Chris,
You almost have it with your last row, but why the looping?
if mod(i,3) = 1 then reset, otherwise add 1
data iris1;
input m1-m4 @@;
count ++ 1;
if mod(_n_,3) = 1 then count = 1;
cards;
5.1 3.5 1.4 0.2 7.0 3.2 4.7 1.4 6.3 3.3 6.0 2.5
4.9 3.0 1.4 0.2 6.4 3.2 4.5...
Hi Chris,
Try placing the dsd option on the infile line. The dsd option will treat two consecutive delimiters as a missing value. I would also add the missover option in case you have missing values at the end of the line.
data test1;
infile datalines dsd missover ;
input n1 n2 n3 ...
Try using last.
data have ;
input name :$1. dateperiod :$6. ;
cards ;
A 200301
A 200901
A 201001
B 200801
B 200901
B 201001
;;;;;
data want ;
set have ;
by name notsorted ;
if last.name ;
run;
proc print;run;
...10:00:00 11.13 1
385000 3/1/2010 8:00:00 11.12 0
385000 3/1/2010 9:00:00 11.12 0
;;;
proc sql ;
create table want(drop=n dttime) as
select h1.*, monotonic() as n, (h2.id ne h1.id and h2.id is not null) as x
from have h1 left join have h2
on 0<(abs(h1.dttime-h2.dttime)/(60*60*24))<=...
SAS has many was to do this type of thing. Here is an example using proc summary/means
data have ;
input Group ID Successes ;
cards ;
1 1 3
1 2 10
1 3 4
2 1 3
2 2 8
2 3 2
3...
...todays day.
For example, try running the following code and see if it matches the output you would expect:
data _null_ ;
start='02Jan00'd;*Start day before end day;
end ='01Jan01'd;
y=intck('year',start,end) ;
z=floor((intck('month',start,end)-(day(end)<day(start)))/12)...
As you have already noted, given the names of your variable, you cannot rename with a variable list.
I would consider using a combination of SQL and the dictionary tables to generate the rename code.
Example using sashelp.class
data have ;
set sashelp.class ;
run;
proc sql noprint...
...that variable as currency.
Simply replace 'put' with 'format' in your example.
data tblCustomer1;
set tblCustomer;
if Salary >= 50000 then Bonus=Salary *0.05;
if Salary <= 50000 then Bonus=Salary *0.25;
Total = Salary+Bonus ;
format Total dollar10.2;
run;
proc print;run;
If CE_DUE_DT has to always be the last day of the previous month (relative to the date being passed to it), I would recommend using the Intnx function to get the first day of that month and subtract 1 to get the last day of the previous month.
Example
data _null_ ;
date = '01SEP10'd ...
Hi Riskassure,
This is look-ahead code.
The ++ performs the same operation as +. Some programmers prefer to use this syntax on sum statements so that it stands out. Consequently _n_ +_n_ < n will work just as well.
The second part of the expression: _n_<n resolves to a boolean value (i.e 1...
...purposes, you can use the missing option and set it to blank.
options missing=' ';
data class ;
set sashelp.class ;
call missing(x,y,z) ;*Create missing numerics x,y,z;
run;
proc report data=class ;
columns _all_ ;
define _all_ / width=10 ;
run;
For characters, a retain...
In the normal data step, the trick is to stop SAS from returning to the top of the implicit loop. Metadata attributes get defined at compilation time, so you can define variables with formats, labels and lengths without having any records.
data step:
data blank1 ;
dummy1 ='';
dummy2 =...
...from tab_a a;
Here is some test data and code I used to get the last sale (by date) for a given year, to test the concept of the above code.
*Jumble data ;
data retail ;
set sashelp.retail ;
ran=ranuni(1234) ;
run;
proc sort data=retail out=sales (drop=ran) ;
by ran ;
run...
Hi Chris,
Hopefully this is what you are looking for (one of many ways):
First transposing, then getting the unique group/counts and using proc summary to perform the counts. The completetypes and classdata options allow proc summary to retrieve the groups that have 0 codes.
data have ...
...added flexibility, you can use the anydtdte type formats and informats to have SAS determine what date informat should be applied to the data.
*Define that date will be in the format month,day,year;
options datestyle = mdy ;
data _null_ ;
input date_char :$10. date_num :anydtdte. ...
...printing the code out to a temporary file, and then executing it (as you would a macro). Here is an example using the sashelp.class dataset:
HTH
*Going to generate the code to rename the worksheets and print out the records for each name;
*Replace this with your absolute path for the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.