DATA Step, Macro, Functions and more

Variable creation

Reply
Occasional Contributor
Posts: 10

Variable creation

[ Edited ]

 

 

 Now,

 

I have the following dataset

I need to create a variable called 'Perfectshot'

let perfect shot=PS

 

1. if all prevously viewable image become 'nonviewable'

and

2. Goodimage = Yes --> becomes 'nonviewable' or measures <10

compare each day to the day1 image

 

 

please help!

Super User
Posts: 17,840

Re: Variable creation

You need to format this post, your table spills over and it doesn't display properly.

For me at least, on Chrome.

Occasional Contributor
Posts: 10

Re: Variable creation

[ Edited ]

Sorry about that..I have attached my table with this post

Thanks!

Super User
Posts: 10,500

Re: Variable creation

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

If you have an existing SAS dataset to share then this link: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

will show how to generate datastep code that you can post or attach as a text file to provide data wo work with.

Occasional Contributor
Posts: 10

Re: Variable creation

person_idvisitdayViewable_1length_1Goodimage_1Viewable_2lengthe_2Goodimage_2Viewable_3length_3Goodimage_3
1day1Yes36NoYes15YesYes15No
1day2Yes19NoYes31YesYes18No
1day3Yes28NoYes27YesYes30No
2day1Yes38NoYes15NoYes49Yes
3day1Yes47NoYes14NoYes41Yes
3day2Yes78No......
4day1Yes74No......
4day2Yes8NoYes7No...
4day3Yes8NoYes7NoYes12No
5day1Yes3NoYes23Yes...
5day2Yes8NoYes15Yes...
5day3Yes7NoYes13Yes...
5day4Yes7NoYes11Yes...
5day5Yes6Nono11Yes...
6day1Yes16Nono12Yes...
6day2Yes17NoYes12Yes...
7day1Yes6NoYes6Yes...
7day2No.NoYes5Yes...
8day1No.NoYes6Yes...
8day2No.NoYes6Yes...
9day1Yes16No......
9day2.........
10day1Yes21No......
10day2Yes24YesYes24yesYes33No
10day3Yes26YesYes26NoYes54No
11day1no27YesYes26No...
11day2Yes10NoYes31YesYes44No
11day3Yes56No......
12day1Yes43No......
12day2Yes41No......
12day3Yes40No......
13day1Yes34No......

 

 

Unfortunately i don thave an existing sas dataset

I will create one and post it

Occasional Contributor
Posts: 10

Re: Variable creation

person_idvisitdayViewable_1length_1Goodimage_1Viewable_2lengthe_2Goodimage_2Viewable_3length_3Goodimage_3
1day1Yes36NoYes15YesYes15No
1day2Yes19NoYes31YesYes18No
1day3Yes28NoYes27YesYes30No
2day1Yes38NoYes15NoYes49Yes
3day1Yes47NoYes14NoYes41Yes
3day2Yes78No......
4day1Yes74No......
4day2Yes8NoYes7No...
4day3Yes8NoYes7NoYes12No
5day1Yes3NoYes23Yes...
5day2Yes8NoYes15Yes...
5day3Yes7NoYes13Yes...
5day4Yes7NoYes11Yes...
5day5Yes6Nono11Yes...
6day1Yes16Nono12Yes...
6day2Yes17NoYes12Yes...
7day1Yes6NoYes6Yes...
7day2No.NoYes5Yes...
8day1No.NoYes6Yes...
8day2No.NoYes6Yes...
9day1Yes16No......
9day2.........
10day1Yes21No......
10day2Yes24YesYes24yesYes33No
10day3Yes26YesYes26NoYes54No
11day1no27YesYes26No...
11day2Yes10NoYes31YesYes44No
11day3Yes56No......
12day1Yes43No......
12day2Yes41No......
12day3Yes40No......
13day1Yes34No......

 

Here is the data

Thanks!

Occasional Contributor
Posts: 10

Re: Variable creation

Here is the sas dataset

I hope someone can help me with this

thanks!

Attachment
Super User
Posts: 10,500

Re: Variable creation

Now in terms of that data you need to expand on:

 

1. if all prevously viewable image become 'nonviewable'

and

Previous to what? Lower index variable in the same row? Previous rows for same day? Previous days?

It may seem obvious to you but your data does not have a "nonviewable" value. What is the definition of nonviewable in this context? Does this apply to multiples of the variables Viewable_1, Viewable_2 and Viewable_3 on one row (and how many), or across rows or across days?

 

2. Goodimage = Yes --> becomes 'nonviewable' or measures <10

compare each day to the day1 image

 

Yor example data above does not have a variable Measures. What does Measures<10 mean in terms of the data above?

Since you have 3 variables named GoodImage then which one? And what does Goodimag=1 becomes 'nonviewable' mean? Point to an example in the data.

 

And given that input, what does the result look like?

Occasional Contributor
Posts: 10

Re: Variable creation

[ Edited ]

Hi,

I have tried to better explain here

 

If all [viewable] = no

Or

Day 1 [Goodimage 1,2,3 ] =no and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =no

And and [viewable 1,2,3]=no

Or

Day1 [Goodimage 1,2,3 ] =yes and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =yes

and [viewable 1,2,3]=no or [viewable 1,2,3]=yes and [length 1,2,3] <10

 

Thanks!

Super User
Posts: 10,500

Re: Variable creation

By your short hand like this: [Goodimage 1,2,3 ] =no do you mean "the value for all 3 of the variable is no"?

So nothing is done for Day 2 if at least one "viewable" = Yes?

 

At this point I am not sure if you are specifying your requirement for all Day 1 records or this process is to be done for each record.

 

You really need to show your results as your requirement:

if all [viewable] = no

Or

Day 1 [Goodimage 1,2,3 ] =no and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =no

And and [viewable 1,2,3]=no

Or

Day1 [Goodimage 1,2,3 ] =yes and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =yes

and [viewable 1,2,3]=no or [viewable 1,2,3]=yes and [length 1,2,3] <10

 

is very poorly stated.

Computers want clearly defined boundaries. From your statement portion:

 

if all [viewable] = no  (what is done in this case )

Or

Day 1 [Goodimage 1,2,3 ] =no and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =no (why do you even specify this as it is apparently a contion to get here)

And and [viewable 1,2,3]=no

Or

Day1 [Goodimage 1,2,3 ] =yes and [viewable 1,2,3]=yes now becomes [Goodimage 1,2,3 ] =yes

and [viewable 1,2,3]=no OR (HOW do we know to use the assignment before the OR or after the Or in this block) [viewable 1,2,3]=yes and [length 1,2,3] <10 (you have apparently one set of conditions but two different results [viewable 1,2,3]=no and [viewable 1,2,3]=yes)

 

I think you are using OR in a non-computer sense. Computer programs look like :

If A or B then do this:

Else IF C or D then do this;

Else Do something else.

 

Please show the actual desired output based on your input as the logic you are using is either incomplete or inconsistent. You may know what the desired outcome is but cannot speak "computer" well enough to describe what you are attempting.

                                                                    

And what value should be assigned to your variable "perfectshot"?

 

 

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