BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
huangyu
Calcite | Level 5

I want to know what wrong my code is.

 

huangyu_0-1697867968856.png

 

my code:

---------------------------------------------

libname b "D:\DATA";
run;
proc sort data= b.ex;
by id;
proc sql;
create table work.md as
select drug,

expenses,
input (count,best.) as count
from b.ex;
quit;

-------------------------------------------

1 ACCEPTED SOLUTION
7 REPLIES 7
huangyu
Calcite | Level 5
1    libname b "D:\DATA";
NOTE: Libref B was successfully assigned as follows:
      Engine:        V9
      Physical Name: D:\DATA
2    run;

3    proc sort data= b.ex;
4    by id;

NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
      real time           3.81 sec
      cpu time            0.78 sec


5    proc sql;
6    create table work.md as
7    select
8    drug,
9    expenses,
10   input (count,best.) as count
11   from b.ex;
ERROR: The following columns were not found in the contributing tables: count.
12   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.16 sec
      cpu time            0.01 sec
Kurt_Bremser
Super User
input (count,best.) as count

This means that you try to convert a character variable to numeric, while keeping the name.

But here

ERROR: The following columns were not found in the contributing tables: count.

you are alerted to the fact that this variable does not exist in the input dataset.

Given the picture you posted, and your subject line, I guess you want the count of observations and sum of expenses per patient. This would be done in SQL like this:

proc sql;
create table md as
  select
    id,
    count(drug) as count,
    sum(expenses) as sum
  from b.ex
  group by id
;
quit;

 

huangyu
Calcite | Level 5

I also wnat to ask how to use "retain + if first.VARIABLE,  if last.VARIABLE" to do the same thing?

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1642 views
  • 0 likes
  • 2 in conversation