BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fiery
Obsidian | Level 7

When I look at this question, I thought the answer should be 4 variables including a new variable ``Group``. However, the correct the answer is 3. I am a bit confused about the IF statement, what is the result for this IF statement then?  Thanks for help. 

If statement.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

There's a stand-alone KEEP statement:

 

keep name height weight;

 

The stand-alone statement applies to the output, not the input.  So the output data set contains only those three variables.  It doesn't matter how many variables are part of the input, or how many variables get created along the way by programming statements.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

There's a stand-alone KEEP statement:

 

keep name height weight;

 

The stand-alone statement applies to the output, not the input.  So the output data set contains only those three variables.  It doesn't matter how many variables are part of the input, or how many variables get created along the way by programming statements.

HB
Barite | Level 11 HB
Barite | Level 11

The IF statement is a pointless red herring.

 

It creates a value of GROUP for records with a value of AGE meeting a condition, but then noting is done with it.  It's stupid and not anything you would write in real life.

 

Fiery
Obsidian | Level 7

Thanks for your reply. Is there something wrong this the IF statement? What if we do want to create a variable Group to set age >=13 to be "Teen". How would you write the programme to make it appear to the output? Thanks! 

Astounding
PROC Star

You would need to add a fourth variable to the list of those being kept:

 

keep name height weight group;

 

The rest of the program could remain unchanged.

Fiery
Obsidian | Level 7
Thanks!

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
  • 5 replies
  • 803 views
  • 1 like
  • 3 in conversation