Thanks!
Can you attach a txt file to hold these data.
Your data's layout is too bad .I Can't copy and paste it into SAS rightly.
Ksharp
?
Proc sql seems to knock down three birds by using one stone:
proc import datafile="h:\book1.csv"
out=have
dbms=csv
replace;
getnames=yes;
run;
proc sql;
create table want as
select *, count(distcd) as c_distcd, substr(put(date, ddmmyy10.),4,7) as monyear,
case when distcd in (1262, 1272) then 1
else 0
end as flag
from have
group by calculated monyear, distcd
order by date, calculated monyear, distcd;
quit;
Haikuo
This is the message I receive when following the above instructions. Is there a way to change your data types on SAS? I'm guessing I need the program to read these numbers as numerical figures
Hi. I tested HaiKuo's code with your sample data,not found a problem. Maybe your variable at IN is a character not a numeric. But there is little choice to change the type of variables in PROC IMPORT. you can
try to use the following.
proc import datafile="h:\book1.csv"
out=have
dbms=csv
replace;
getnames=yes; guessingrows=32767;
run;
Sure, there is no guarantee to make it numeric.
So if you can, After IMPORT it , you can change it on your own.
new_distcd=input(distcd,best32.);
Ksharp
Thanks Ksharp
Hi.
HaiKuo's code is good enough.
From your Log, Maybe distribution code is being translated into Character variable. Try it for Character varaibel.
case when distcd in ("1262","1272") then 1
Ksharp
almost there though I need a numeric statment for the monthyear conversion?
The ERROR information tell you that put(date, ddmmyy10.) DATE is a character varaible ,therefore you don't need put() anymore ,you can use substr() directly if DATE looks like date format .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.