Published on :
Data Manipulation CREATION_INTERNE

Demonstration of the CHOOSEC function

This code is also available in: Deutsch Español Français
The script demonstrates how to select a specific character-type argument from a list using the `CHOOSEC` function. It tests selection by positive index and by negative index (counting from the end).
Data Analysis

Type : CREATION_INTERNE


The processed values are literal character strings passed directly as function arguments.

1 Code Block
DATA STEP
Explanation :
This Data Step block does not create an output table (_null_). It calculates two variables: 'third' (3rd element) and 'last' (last element via index -1) using the CHOOSEC function, and writes the results to the SAS log.
Copied!
1DATA _null_ ;
2 third=choosec(3,'dog','cat','rat','bat') ;
3 put third= ;
4 last=choosec(-1,'dog','cat','rat','bat') ;
5 put last= ;
6RUN ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.