turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- i want a calculated values of number of subjects

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 06:52 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 07:01 AM

Give sample of your desired output..

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 07:05 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 07:51 AM

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 08:04 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-07-2015 08:24 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-08-2015 03:29 AM

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(%)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-08-2015 04:38 AM

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.