All data processed in this script is created internally via 'DATALINES' blocks directly included in the SAS code. No external data sources or SASHELP libraries are used for data input.
1 Code Block
PROC FORMAT
Explanation : Defines a numeric format named 'readdate'. This format maps value 1 to the 'date7.' read format (day-month-two-digit-year) and value 2 to the 'mmddyy8.' format (month/day/two-digit-year). It is used to dynamically interpret character strings as SAS dates.
Copied!
proc format;
value readdate 1='date7.'
2='mmddyy8.';
run;
1
PROC FORMAT;
2
value readdate 1='date7.'
3
2='mmddyy8.';
4
RUN;
2 Code Block
OPTIONS
Explanation : Sets the 'yearcutoff' system option to 1920. This option indicates that any two-digit year less than 'yearcutoff' (e.g., '00' to '19') will be considered to belong to the 21st century (20xx), while years equal to or greater (e.g., '20' to '99') will be considered to belong to the 20th century (19xx).
Copied!
options yearcutoff=1920;
1
options yearcutoff=1920;
3 Code Block
DATA STEP Data
Explanation : Creates the 'fixdates' dataset by reading raw in-line data. The 'dateinformat' variable is created by applying the 'readdate' format to the 'source' variable, which generates the appropriate date format string. Then, the 'INPUTN' function uses this dynamic format string to convert the 'start' character string into a numeric SAS date value ('newdate').
Explanation : Displays the content of the newly created 'fixdates' dataset, allowing verification of date conversion and data structure.
Copied!
proc print;run;
1
PROC PRINT;RUN;
5 Code Block
PROC FORMAT
Explanation : Defines a numeric format 'typefmt' that maps values 1, 2, and 3 to specific character input format names ('$groupx', '$groupy', '$groupz'). In addition, it defines three character input formats ('INVALUE'): '$groupx', '$groupy', and '$groupz'. Each of these formats maps the strings 'positive', 'negative', and 'neutral' to different categorical terms (e.g., 'agree', 'accept', 'pass').
Explanation : Creates the 'answers' dataset by reading raw in-line data. The 'respinformat' variable is created by applying the 'typefmt' format to the 'type' variable, which generates the appropriate character input format name (e.g., '$groupx'). Then, the 'INPUTC' function uses this dynamic format name to map the 'response' character string to a standardized categorical value ('word').
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.