Help using Base SAS procedures

Re:

Reply
Contributor
Posts: 60

Re:

Thanks!

Super User
Posts: 9,691

Re: RE: COMMAND HELP

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

Contributor
Posts: 60

Re: RE: COMMAND HELP

?

Respected Advisor
Posts: 3,124

Re: RE: COMMAND HELP

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

Contributor
Posts: 60

Re: RE: COMMAND HELP

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

Super User
Posts: 9,691

Re: RE: COMMAND HELP

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

Contributor
Posts: 60

Re: RE: COMMAND HELP

Thanks Ksharp


Super User
Posts: 9,691

Re: RE: COMMAND HELP

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

Contributor
Posts: 60

Re: RE: COMMAND HELP

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

Super User
Posts: 9,691

Re: RE: COMMAND HELP

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 .

Ask a Question
Discussion stats
  • 9 replies
  • 313 views
  • 0 likes
  • 3 in conversation