Posts

Showing posts with the label input

How to convert numeric date values into character and from character date values into numeric using DATASTEP, PROC SQL and ARRAYS

1) Converting character date values into numeric: /*I) Using the DATASTEP:*/ 1) Data dates; input cdate $9.; cards; 16-apr-07 01-01-07 02-jun-07 13-sep-07 ; run; Data Convert; set dates; Date = input ( cdate , ANYDTDTE9.); format date date7.; run; 2) Data dates ; input cdate $9.; cards; 16-apr-2007 01-01-2007 02-jun-2007 13-sep-2007 ; run; Data Convert ; set dates; Date = input ( cdate , ANYDTDTE11.); format date date9.; run ; *II) Using Proc SQL; *Numeric date variable can be converted to character date variable by using the PUT function within PROC SQL.; proc sql; create table date_char as select PUT(date, date9.) as ndate from date_num; quit; *Character date variable can be converted to numeric date variable by using the INPUT function within PROC SQL.; Proc sql; create table date_num as select INPUT (date, mmddyy10.) as ndate format= mmddyy10. from date_char; quit ; Or Proc sql ; create table date_num as sel...

Getting the Data into SAS

GETTING DATA INTO SAS direct link: http://www.biostat.ucla.edu/course/m403b/M403B2005_2DataInput.pdf 1. Importing data from other sources • Use DBMS Copy, STAT Transfer, or some other software that performs similar functions. • Use SAS/ACCESS or the SAS Import feature in Windows. • Use PROC IMPORTS to read certain types of data files. • Create a raw data (ASCII) file then use INPUT and INFILE statements to read the raw data file in SAS programs. 2. Creating SAS data sets with raw (ASCII) data files • Data are placed within the SAS program directly after the DATALINES or CARDS statement. Use INPUT statement to read the data. *** Read data within SAS program as SAS data file ***; DATA survey; INPUT Q1Major Q2Degree Q3SASpast Q4ProjData Q5SASexprn Q6SASfutur; DATALINES; 2 1 1 1 2 8 2 2 0 0 0 7 2 1 0 0 1 4 2 1 0 1 0 8 more raw data lines ; RUN ; • In the above example, – Spaces (or other types of delimiters) are required between data values – Missing values must be specified (blank sp...

SAS Interview Questions: Base SAS

Very Basic: What SAS statements would you code to read an external raw data file into a DATA step? You would use the INFILE statement to specify the location of the external raw data file, and the INPUT statement to read in the data into the variables in a SAS dataset. How do you read in the variables that you need? You use the INPUT statement with specific column pointers, such as @5 or 12-17 , to define where each variable is located in the raw data file. Are you familiar with special input delimiters? How are they used? Yes, special input delimiters like DLM and DSD are used to specify how fields are separated in the data. They are included in the INFILE statement. For example, the DLM option can be used to specify a comma as a delimiter for CSV files. The DSD option is used for comma-separated values (CSV) files and treats consecutive delimiters as missing values and ignores delimiters enclosed in quotation marks. If reading a variable-length file with fixed inp...

Convert values from character to numeric or from numeric to character.

Image
Convert values from character to numeric or from numeric to character\Convert variable values using either the INPUT or PUT function. Convert a character value to a numeric value by using the INPUT function. Specify a numeric informat that best describes how to Read the data value into the numeric variable. When changing types a new variable name is required. If you need to keep the original variable name for the new type, use the RENAME = option as illustrated in Sample 2. data char; input string : $8. date : $6.; numeric= input (string, 8.); sasdate= input (date, mmddyy6.); format sasdate mmddyy10.; datalines ; 1234.56 031704 3920 123104; proc print; run ; data now_num; input num date: mmddyy6.; datalines ; 123456 110204 1000 120504;   run; data now_char ; set now_num (rename=(num=oldnum date=olddate)); num = put (oldnum,6. -L); date = put ( olddate , date9 .); run ; proc print ; run ; Source: support.sas.com Here ...