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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 643 views
  • 0 likes
  • 2 in conversation