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
- /
- General Programming
- /
- Can you help me please immediately

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

10-04-2015 09:08 PM

Hello,

I have this question " Create a new variable called project2 and add 10 points to the project grade of the following students A,B,C,D (keep the grades of other students same)"

Can you please help me out ?

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

10-04-2015 11:06 PM - edited 10-04-2015 11:13 PM

Something similar to this:

`if student in ('A', 'B', 'C') then grade = grade + 10;`

BTW, it would be helpful if you summarised your problem in the title rather than ask for help because that applies to most posters...

Perhaps something like: SAS Coding Question

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

10-05-2015 09:46 AM

I partially agree with SASKiwi's answer except that the grade variable will be over written and you asked for a new variable. Therefore I suggest:

`if student in ('A', 'B', 'C') then project2 = project + 10;`

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

10-05-2015 10:00 AM

Hi, another idea ...

**data x;****input student :$1. grade @@;****datalines;****A 50 B 60 C 70 D 33****;**

**data y;****set x;****grade + 10*(student in ('A' 'B' 'C'));****run;**

data set Y ...

**Obs student grade**

**1 A 60****2 B 70****3 C 80****4 D 33**

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

10-05-2015 02:09 PM

Here is a slight variation of Mike's example. This one handles missing values.

```
data x;
input student $ grade;
datalines;
A 50
B 60
C .
D 33
;
run;
data y;
set x;
if student in ('A','B','C','D') then project2 = sum(grade, 10);
run;
```

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

10-05-2015 05:00 PM

Hi, the SUM statement also ignores mising values.

**data x;****input student :$1. grade @@;****datalines;****A 50 B 60 C . D 33****;**

**data y;****set x;****grade + 10*(student in ('A' 'B' 'C'));****run;**

data set Y ..

**Obs student grade**

**1 A 60****2 B 70****3 C 10****4 D 33**

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

10-05-2015 08:00 PM

You are right ... the boolean statement student in ('A' 'B' 'C') evaluates to 1; thus, for student 'C', 1*10 = 10.

In short, the sum operator (+) used in conjunction with the product of a boolean result would result in a non-missing value.