BookmarkSubscribeRSS Feed
spraynardz90
Calcite | Level 5

Thanks!

9 REPLIES 9
Ksharp
Super User

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

spraynardz90
Calcite | Level 5

?

Haikuo
Onyx | Level 15

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

spraynardz90
Calcite | Level 5

Capture.JPG

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

Ksharp
Super User

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

spraynardz90
Calcite | Level 5

Thanks Ksharp


Ksharp
Super User

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

spraynardz90
Calcite | Level 5

Capture.JPGalmost there though I need a numeric statment for the monthyear conversion?

Ksharp
Super User

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 .

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