BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

I have a dataset which has values from negative and positive.

ex:

subj   value  visit    trt

101    -1.3      3       A

102    2.1        3       A

103    -1.2      3         B

101     3          4      A

102    1          4        B

 

I want to have number of subjects and percentage who have negative(value) as visit 3 and positive value after visit3. Also another count and percentage of subjects who are postive atleast ones .

 

Can anyone help me

7 REPLIES 7
mohamed_zaki
Barite | Level 11

Give sample of your desired output..

vraj1
Quartz | Level 8
I need N (%) for Subjects tested negative at visit 3, but positive during treatment and N (%) Subjects tested positive at least once during treatment period
PaigeMiller
Diamond | Level 26

Here's the code to count the number of times this happens, I figure you can turn that into a percentage

 

UNTESTED CODE

 

proc sort data=have;
    by subj visit;
run;

data count;
    set have;
    prev_value=lag(value);
    if visit=4 and prev_value<0 and value>0 then output;
run;
--
Paige Miller
vraj1
Quartz | Level 8

Hi,

 

I am sorry. I may be confusing you.

 

I need  Subjects whose values are in negative(ex: -1.334) at visit 3, but positive(ex: 1.23) during treatment and  Subjects tested positive(ex: positive values at least once) at least once during treatment period

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like this should suffice:

proc sql;
  create table WANT as
  select  count(distinct COALESCE(A.SUBJ,B.SUBJ)) as SUBJ_COUNT,
          (select count(distinct SUBJ) deom HAVE) as TOTAL_SUBJ,
          CALCULATED SUBJ_COUNT / CALCULATED TOTAL_SUBJ * 100 as PCENT
  from    (select * from HAVE where VISIT=3) A
  full join (select * from HAVE where VISIT=4) B
  on      A.SUBJ=B.SUBJ
  where   A.VALUE < 0 and B.VALUE > 0;
run;
vraj1
Quartz | Level 8

m sorry as i am new to sas i am still finding it difficult.

 

what will the above program do and what does deom mean?

 

I want 2 counts 

 

1)Subjects tested positive at least once during treatment period   - N(%)

 

2) Subjects tested negative  at visit 3, but positive during treatment - N(%)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ah, ok so you are just learning SAS.  Might I suggest you go through the help videos, and documentation and start off with the underlying language.  It looks like you are trying to program some clicnical output, there are a number of things to consider.  If your doing this for leraning, then best to understand the language first.  If you doing it for work, then you need to ask collegues as its likely they already have macro libraries, set programs, or examples that you can directly use.

At a basic level you need to do three things:

1)  Get big N, i.e. the number of distinct subjects in the dataset.  You can do this in a number of ways, proc freq/means etc.  I tend to use SQL for this:

proc sql;
   create table N as
   select count(distinct SUBJ) as N
   from   HAVE;
quit;

So (and I am trying to keep this basic, all this can be compressed and coded differently, but it is to show th logic), this creates a dataset with numbr of distinct subjects.

2)  Get number of subjects with test positive:

proc sql;
   create table POSITVE as
   select count(distinct SUBJ) as N
   from   HAVE
   where  RESULT > 0;
quit;

3)  Get number of subjects with negative at 3, but not at 4 - this requires one fo two things, either retaining the V3 record down the dataset or merging that value back onto the dataset:

I will do retain (assumes the data is sorted by subject visit), what this will do is create a dataset with all records not visit 3, but which contain visit 3 data in v3_value:

data test3;
  set have;
  by subj;
  retain v3_value;
  if first.subj then v3_value=.;
  if visit=3 then v3_value=result;
  else output;
run;

Then simply do a count:

proc sql;
   create table WANT as
   select  count(distinct SUBJ)
   from    TEST3
   where  RESULT > 0 and V3_VALUE < 0;
quit;

You now have your thee necessary counts, and you can merge these together, or set them together however your output requires.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 979 views
  • 0 likes
  • 4 in conversation