Discussion:
converting char to num and num to char in datastep
(too old to reply)
t***@hotpop.com
2006-05-01 20:03:20 UTC
Permalink
Hi All

How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.

Toby





While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
toby dunn
2006-05-01 20:17:01 UTC
Permalink
Toby ,

It is simple use the put function to go from numeric to character and input
to go from character to numeric.

data one ;

Num1 = 123 ;
Char1 = '987' ;

Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;

Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;

put _all_ ;
run ;




Toby Dunn





From: ***@HOTPOP.COM
Reply-To: ***@HOTPOP.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700

Hi All

How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.

Toby





While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
t***@hotpop.com
2006-05-01 21:28:38 UTC
Permalink
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.

I can instantly replace a variable with another value.
q10hlpicp = 6 - q10hlpicp;

I think its not much different:
f8=input(f8,$50.);
But why does this not work?

Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and input
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
t***@hotpop.com
2006-05-02 17:23:03 UTC
Permalink
Ok, got it to use the put function. What about if I dont know the format
of the source variable in advance?

I though vformat() returns a format name??? (at least according tot the
onlinedoc, but maybe they are lying there)

Toby


data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a));
1 !+f8=put(f8a,vformat(f8a)); f9=put
-------
85
76
NOTE: Line generated by the CALL EXECUTE routine.
2 +(f9a,vformat(f8a)); f10=put(f10a,vformat(f8a));
f13=put(f13a,vformat(f8a)); f0=2; run;
------- ------- -------
85 85 85
76 76 76

ERROR 85-322: Expecting a format name.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and input
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Gary McQuown
2006-05-01 20:28:20 UTC
Permalink
Toby,

You can find what you need at
http://support.sas.com/91doc/getDoc/lrdict.hlp/a000245860.htm under
"put" and "input".

The information is there, you just need to know where to look. Your
frustration is a sign that the search engine still needs to be improved
upon.

My $.02;
Gary




-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@HOTPOP.COM
Sent: Monday, May 01, 2006 3:03 PM
To: SAS-***@LISTSERV.UGA.EDU
Subject: converting char to num and num to char in datastep

Hi All

How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.

Toby





While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.
Joe Whitehurst
2006-05-01 20:30:13 UTC
Permalink
Toby,

Ouch! You must not have seen:
http://support.sas.com/onlinedoc/913/docMainpage.jsp

The SAS System is probably much, much wider and deeper than other
software systems you have experienced and, given the sheer volume of
documentation material, I think SAS does an excellent job of making
such documentation accessible. You can peruse functions and call
routines by category if you wish:
Functions and CALL Routines

Functions and CALL Routines by Category


Categories and Descriptions of Functions and CALL Routines Category
Functions and CALL Routines Description
Array DIM Function
Returns the number of elements in an array

HBOUND Function
Returns the upper bound of an array

LBOUND Function
Returns the lower bound of an array
Bitwise Logical Operations BAND Function
Returns the bitwise logical AND of two arguments

BLSHIFT Function
Returns the bitwise logical left shift of two arguments

BNOT Function
Returns the bitwise logical NOT of an argument

BOR Function
Returns the bitwise logical OR of two arguments

BRSHIFT Function
Returns the bitwise logical right shift of two arguments

BXOR Function
Returns the bitwise logical EXCLUSIVE OR of two arguments
Character String Matching CALL PRXCHANGE Routine
Performs a pattern-matching replacement

CALL PRXDEBUG Routine
Enables Perl regular expressions in a DATA step to send debug output
to the SAS log

CALL PRXFREE Routine
Frees unneeded memory that was allocated for a Perl regular expression

CALL PRXNEXT Routine
Returns the position and length of a substring that matches a pattern
and iterates over multiple matches within one string

CALL PRXPOSN Routine
Returns the start position and length for a capture buffer

CALL PRXSUBSTR Routine
Returns the position and length of a substring that matches a pattern

CALL RXCHANGE Routine
Changes one or more substrings that match a pattern

CALL RXFREE Routine
Frees memory allocated by other regular expression (RX) functions and
CALL routines

CALL RXSUBSTR Routine
Finds the position, length, and score of a substring that matches a pattern

PRXCHANGE Function
Performs a pattern-matching replacement

PRXMATCH Function
Searches for a pattern match and returns the position at which the
pattern is found

PRXPAREN Function
Returns the last bracket match for which there is a match in a pattern

PRXPARSE Function
Compiles a Perl regular expression (PRX) that can be used for pattern
matching of a character value

PRXPOSN Function
Returns the value for a capture buffer

RXMATCH Function
Finds the beginning of a substring that matches a pattern

RXPARSE Function
Parses a pattern
Character ANYALNUM Function
Searches a character string for an alphanumeric character and returns
the first position at which it is found

ANYALPHA Function
Searches a character string for an alphabetic character and returns
the first position at which it is found

ANYCNTRL Function
Searches a character string for a control character and returns the
first position at which it is found

ANYDIGIT Function
Searches a character string for a digit and returns the first
position at which it is found

ANYFIRST Function
Searches a character string for a character that is valid as the
first character in a SAS variable name under VALIDVARNAME=V7, and
returns the first position at which that character is found

ANYGRAPH Function
Searches a character string for a graphical character and returns the
first position at which it is found

ANYLOWER Function
Searches a character string for a lowercase letter and returns the
first position at which it is found

ANYNAME Function
Searches a character string for a character that is valid in a SAS
variable name under VALIDVARNAME=V7, and returns the first position at
which that character is found

ANYPRINT Function
Searches a character string for a printable character and returns the
first position at which it is found

ANYPUNCT Function
Searches a character string for a punctuation character and returns
the first position at which it is found

ANYSPACE Function
Searches a character string for a white-space character (blank,
horizontal and vertical tab, carriage return, line feed, form feed)
and returns the first position at which it is found

ANYUPPER Function
Searches a character string for an uppercase letter and returns the
first position at which it is found

ANYXDIGIT Function
Searches a character string for a hexadecimal character that
represents a digit and returns the first position at which that
character is found

BYTE Function
Returns one character in the ASCII or the EBCDIC collating sequence

CALL CATS Routine
Concatenates character strings and removes leading and trailing blanks

CALL CATT Routine
Concatenates character strings and removes trailing blanks

CALL CATX Routine
Concatenates character strings, removes leading and trailing blanks,
and inserts separators

CALL COMPCOST Routine
Sets the costs of operations for later use by the COMPGED function

CALL MISSING Routine
Assigns a missing value to the specified character or numeric variables.

CALL SCAN Routine
Returns the position and length of a given word from a character expression

CALL SCANQ Routine
Returns the position and length of a given word from a character
expression, and ignores delimiters that are enclosed in quotation
marks

CAT Function
Concatenates character strings without removing leading or trailing blanks

CATS Function
Concatenates character strings and removes leading and trailing blanks

CATT Function
Concatenates character strings and removes trailing blanks

CATX Function
Concatenates character strings, removes leading and trailing blanks,
and inserts separators

CHOOSEC Function
Returns a character value that represents the results of choosing
from a list of arguments

CHOOSEN Function
Returns a numeric value that represents the results of choosing from
a list of arguments

COALESCEC Function
Returns the first non-missing value from a list of character arguments.

COLLATE Function
Returns an ASCII or EBCDIC collating sequence character string

COMPARE Function
Returns the position of the leftmost character by which two strings
differ, or returns 0 if there is no difference

COMPBL Function
Removes multiple blanks from a character string

COMPGED Function
Compares two strings by computing the generalized edit distance

COMPLEV Function
Compares two strings by computing the Levenshtein edit distance

COMPRESS Function
Removes specific characters from a character string

COUNT Function
Counts the number of times that a specific substring of characters
appears within a character string that you specify

COUNTC Function
Counts the number of specific characters that either appear or do not
appear within a character string that you specify

DEQUOTE Function
Removes matching quotation marks from a character string that begins
with an individual quotation mark and deletes everything that is to
the right of the closing quotation mark

FIND Function
Searches for a specific substring of characters within a character
string that you specify

FINDC Function
Searches for specific characters that either appear or do not appear
within a character string that you specify

IFC Function
Returns a character value of an expression based on whether the
expression is true, false, or missing

IFN Function
Returns a numeric value of an expression based on whether the
expression is true, false, or missing

INDEX Function
Searches a character expression for a string of characters

INDEXC Function
Searches a character expression for specific characters

INDEXW Function
Searches a character expression for a specified string as a word

LEFT Function
Left aligns a SAS character expression

LENGTH Function
Returns the length of a non-blank character string, excluding
trailing blanks, and returns 1 for a blank character string

LENGTHC Function
Returns the length of a character string, including trailing blanks

LENGTHM Function
Returns the amount of memory (in bytes) that is allocated for a
character string

LENGTHN Function
Returns the length of a non-blank character string, excluding
trailing blanks, and returns 0 for a blank character string

LOWCASE Function
Converts all letters in an argument to lowercase

MISSING Function
Returns a numeric result that indicates whether the argument contains
a missing value

NLITERAL Function
Converts a character string that you specify to a SAS name literal (n-literal)

NOTALNUM Function
Searches a character string for a non-alphanumeric character and
returns the first position at which it is found

NOTALPHA Function
Searches a character string for a non-alphabetic character and
returns the first position at which it is found

NOTCNTRL Function
Searches a character string for a character that is not a control
character and returns the first position at which it is found

NOTDIGIT Function
Searches a character string for any character that is not a digit and
returns the first position at which that character is found

NOTFIRST Function
Searches a character string for an invalid first character in a SAS
variable name under VALIDVARNAME=V7, and returns the first position at
which that character is found

NOTGRAPH Function
Searches a character string for a non-graphical character and returns
the first position at which it is found

NOTLOWER Function
Searches a character string for a character that is not a lowercase
letter and returns the first position at which that character is found

NOTNAME Function
Searches a character string for an invalid character in a SAS
variable name under VALIDVARNAME=V7, and returns the first position at
which that character is found

NOTPRINT Function
Searches a character string for a non-printable character and returns
the first position at which it is found

NOTPUNCT Function
Searches a character string for a character that is not a punctuation
character and returns the first position at which it is found

NOTSPACE Function
Searches a character string for a character that is not a white-space
character (blank, horizontal and vertical tab, carriage return, line
feed, form feed) and returns the first position at which it is found

NOTUPPER Function
Searches a character string for a character that is not an uppercase
letter and returns the first position at which that character is found

NOTXDIGIT Function
Searches a character string for a character that is not a hexadecimal
digit and returns the first position at which that character is found

NVALID Function
Checks a character string for validity for use as a SAS variable name
in a SAS statement

PROPCASE Function
Converts all words in an argument to proper case

QUOTE Function
Adds double quotation marks to a character value

RANK Function
Returns the position of a character in the ASCII or EBCDIC collating sequence

REPEAT Function
Repeats a character expression

REVERSE Function
Reverses a character expression

RIGHT Function
Right aligns a character expression

SCAN Function
Selects a given word from a character expression

SCANQ Function
Returns the nth word from a character expression, ignoring delimiters
that are enclosed in quotation marks

SOUNDEX Function
Encodes a string to facilitate searching

SPEDIS Function
Determines the likelihood of two words matching, expressed as the
asymmetric spelling distance between the two words

STRIP Function
Returns a character string with all leading and trailing blanks removed

SUBPAD Function
Returns a substring that has a length you specify, using blank
padding if necessary

SUBSTR (left of =) Function
Replaces character value contents

SUBSTR (right of =) Function
Extracts a substring from an argument

SUBSTRN Function
Returns a substring, allowing a result with a length of zero

TRANSLATE Function
Replaces specific characters in a character expression

TRANTAB Function
Transcodes a data string by using a translation table

TRANWRD Function
Replaces or removes all occurrences of a word in a character string

TRIM Function
Removes trailing blanks from character expressions and returns one
blank if the expression is missing

TRIMN Function
Removes trailing blanks from character expressions and returns a null
string (zero blanks) if the expression is missing

UPCASE Function
Converts all letters in an argument to uppercase

VERIFY Function
Returns the position of the first character that is unique to an expression
Currency Conversion EUROCURR Function
Converts one European currency to another
DBCS KCOMPARE Function
Returns the result of a comparison of character strings

KCOMPRESS Function
Removes specific characters from a character string

KCOUNT Function
Returns the number of double-byte characters in a string

KCVT Function
Converts data from an encoding code to another encoding code

KINDEX Function
Searches a character expression for a string of characters

KINDEXC Function
Searches a character expression for specific characters

KLEFT Function
Left aligns a character expression by removing unnecessary leading
DBCS blanks and SO/SI

KLENGTH Function
Returns the length of an argument

KLOWCASE Function
Converts all letters in an argument to lowercase

KREVERSE Function
Reverses a character expression

KRIGHT Function
Right aligns a character expression by trimming trailing DBCS blanks and SO/SI

KSCAN Function
Selects a specific word from a character expression

KSTRCAT Function
Concatenates two or more character strings

KSUBSTR Function
Extracts a substring from an argument

KSUBSTRB Function
Extracts a substring from an argument according to the byte position
of the substring in the argument

KTRANSLATE Function
Replaces specific characters in a character expression

KTRIM Function
Removes trailing DBCS blanks and SO/SI from character expressions

KTRUNCATE Function
Truncates a numeric value to a specified length

KUPCASE Function
Converts all single-byte letters in an argument to uppercase

KUPDATE Function
Inserts, deletes, and replaces character value contents

KUPDATEB Function
Inserts, deletes, and replaces the contents of the character value
according to the byte position of the character value in the argument

KVERIFY Function
Returns the position of the first character that is unique to an expression
Date and Time DATDIF Function
Returns the number of days between two dates

DATE Function
Returns the current date as a SAS date value

DATEJUL Function
Converts a Julian date to a SAS date value

DATEPART Function
Extracts the date from a SAS datetime value

DATETIME Function
Returns the current date and time of day as a SAS datetime value

DAY Function
Returns the day of the month from a SAS date value

DHMS Function
Returns a SAS datetime value from date, hour, minute, and second

HMS Function
Returns a SAS time value from hour, minute, and second values

HOUR Function
Returns the hour from a SAS time or datetime value

INTCK Function
Returns the integer count of the number of interval boundaries
between two dates, two times, or two datetime values

INTNX Function
Increments a date, time, or datetime value by a given interval or
intervals, and returns a date, time, or datetime value

JULDATE Function
Returns the Julian date from a SAS date value

JULDATE7 Function
Returns a seven-digit Julian date from a SAS date value

MDY Function
Returns a SAS date value from month, day, and year values

MINUTE Function
Returns the minute from a SAS time or datetime value

MONTH Function
Returns the month from a SAS date value

NLDATE Function
Converts the SAS date value to the date value of the specified locale
using the date-format modifiers

NLDATM Function
Converts the SAS datetime values to the time value of the specified
locale using the datetime format modifiers

NLTIME Function
Converts the SAS time or datetime value to the time value of the
specified locale using the time-format modifiers

QTR Function
Returns the quarter of the year from a SAS date value

SECOND Function
Returns the second from a SAS time or datetime value

TIME Function
Returns the current time of day

TIMEPART Function
Extracts a time value from a SAS datetime value

TODAY Function
Returns the current date as a SAS date value

WEEK Function
Returns the week number value

WEEKDAY Function
Returns the day of the week from a SAS date value

YEAR Function
Returns the year from a SAS date value

YRDIF Function
Returns the difference in years between two dates

YYQ Function
Returns a SAS date value from the year and quarter
Descriptive Statistics CSS Function
Returns the corrected sum of squares

CV Function
Returns the coefficient of variation

GEOMEAN Function
Returns the geometric mean

GEOMEANZ Function
Returns the geometric mean, using zero fuzzing

HARMEAN Function
Returns the harmonic mean

HARMEANZ Function
Returns the harmonic mean, using zero fuzzing

IQR Function
Returns the interquartile range

KURTOSIS Function
Returns the kurtosis

LARGEST Function
Returns the kth largest non-missing value

MAD Function
Returns the median absolute deviation from the median

MAX Function
Returns the largest value

MEAN Function
Returns the arithmetic mean (average)

MEDIAN Function
Computes median values

MIN Function
Returns the smallest value

MISSING Function
Returns a numeric result that indicates whether the argument contains
a missing value

N Function
Returns the number of nonmissing values

NMISS Function
Returns the number of missing values

ORDINAL Function
Returns any specified order statistic

PCTL Function
Computes percentiles

RANGE Function
Returns the range of values

RMS Function
Returns the root mean square

SKEWNESS Function
Returns the skewness

SMALLEST Function
Returns the kth smallest nonmissing value

STD Function
Returns the standard deviation

STDERR Function
Returns the standard error of the mean

SUM Function
Returns the sum of the nonmissing arguments

USS Function
Returns the uncorrected sum of squares

VAR Function
Returns the variance
External Files DCLOSE Function
Closes a directory that was opened by the DOPEN function

DCREATE Function
Creates an external directory

DINFO Function
Returns information about a directory

DNUM Function
Returns the number of members in a directory

DOPEN Function
Opens a directory and returns a directory identifier value

DOPTNAME Function
Returns directory attribute information

DOPTNUM Function
Returns the number of information items that are available for a directory

DREAD Function
Returns the name of a directory member

DROPNOTE Function
Deletes a note marker from a SAS data set or an external file

FAPPEND Function
Appends the current record to the end of an external file

FCLOSE Function
Closes an external file, directory, or directory member

FCOL Function
Returns the current column position in the File Data Buffer (FDB)

FDELETE Function
Deletes an external file or an empty directory

FEXIST Function
Verifies the existence of an external file associated with a fileref

FGET Function
Copies data from the File Data Buffer (FDB) into a variable

FILEEXIST Function
Verifies the existence of an external file by its physical name

FILENAME Function
Assigns or deassigns a fileref to an external file, directory, or
output device

FILEREF Function
Verifies that a fileref has been assigned for the current SAS session

FINFO Function
Returns the value of a file information item

FNOTE Function
Identifies the last record that was read and returns a value that
FPOINT can use

FOPEN Function
Opens an external file and returns a file identifier value

FOPTNAME Function
Returns the name of an item of information about a file

FOPTNUM Function
Returns the number of information items that are available for an
external file

FPOINT Function
Positions the read pointer on the next record to be read

FPOS Function
Sets the position of the column pointer in the File Data Buffer (FDB)

FPUT Function
Moves data to the File Data Buffer (FDB) of an external file,
starting at the FDB's current column position

FREAD Function
Reads a record from an external file into the File Data Buffer (FDB)

FREWIND Function
Positions the file pointer to the start of the file

FRLEN Function
Returns the size of the last record read, or, if the file is opened
for output, returns the current record size

FSEP Function
Sets the token delimiters for the FGET function

FWRITE Function
Writes a record to an external file

MOPEN Function
Opens a file by directory id and member name, and returns the file
identifier or a 0

PATHNAME Function
Returns the physical name of a SAS data library or of an external
file, or returns a blank

SYSMSG Function
Returns the text of error messages or warning messages from the last
data set or external file function execution

SYSRC Function
Returns a system error number
External Routines CALL MODULE Routine
Calls the external routine without any return code

CALL MODULEI Routine
Calls the external routine without any return code (in IML environment only)

MODULEC Function
Calls an external routine and returns a character value

MODULEIC Function
Calls an external routine and returns a character value (in IML
environment only)

MODULEIN Function
Calls an external routine and returns a numeric value (in IML
environment only)

MODULEN Function
Calls an external routine and returns a numeric value
Financial COMPOUND Function
Returns compound interest parameters

CONVX Function
Returns the convexity for an enumerated cash flow

CONVXP Function
Returns the convexity for a periodic cash flow stream, such as a bond

DACCDB Function
Returns the accumulated declining balance depreciation

DACCDBSL Function
Returns the accumulated declining balance with conversion to a
straight-line depreciation

DACCSL Function
Returns the accumulated straight-line depreciation

DACCSYD Function
Returns the accumulated sum-of-years-digits depreciation

DACCTAB Function
Returns the accumulated depreciation from specified tables

DEPDB Function
Returns the declining balance depreciation

DEPDBSL Function
Returns the declining balance with conversion to a straight-line depreciation

DEPSL Function
Returns the straight-line depreciation

DEPSYD Function
Returns the sum-of-years-digits depreciation

DEPTAB Function
Returns the depreciation from specified tables

DUR Function
Returns the modified duration for an enumerated cash flow

DURP Function
Returns the modified duration for a periodic cash flow stream, such as a bond

INTRR Function
Returns the internal rate of return as a fraction

IRR Function
Returns the internal rate of return as a percentage

MORT Function
Returns amortization parameters

NETPV Function
Returns the net present value as a fraction

NPV Function
Returns the net present value with the rate expressed as a percentage

PVP Function
Returns the present value for a periodic cash flow stream with
repayment of principal at maturity, such as a bond

SAVING Function
Returns the future value of a periodic saving

YIELDP Function
Returns the yield-to-maturity for a periodic cash flow stream, such as a bond
Hyperbolic COSH Function
Returns the hyperbolic cosine

SINH Function
Returns the hyperbolic sine

TANH Function
Returns the hyperbolic tangent
Macro CALL EXECUTE Routine
Resolves an argument and issues the resolved value for execution

CALL SYMPUT Routine
Assigns DATA step information to a macro variable

CALL SYMPUTX Routine
Assigns a value to a macro variable and removes both leading and
trailing blanks

RESOLVE Function
Returns the resolved value of an argument after it has been processed
by the macro facility

SYMEXIST Function
Returns an indication of the existence of a macro variable

SYMGET Function
Returns the value of a macro variable during DATA step execution

SYMGLOBL Function
Returns an indication as to whether a macro variable is in a global
scope to the DATA step during DATA step execution.

SYMLOCAL Function
Returns an indication as to whether a macro variable is in a local
scope to the DATA step during DATA step execution
Mathematical ABS Function
Returns the absolute value

AIRY Function
Returns the value of the airy function

BETA Function
Returns the value of the beta function

CALL ALLPERM Routine
Generates all permutations of the values of several variables

CALL LOGISTIC Routine
Returns the logistic value

CALL SOFTMAX Routine
Returns the softmax value

CALL STDIZE Routine
Standardizes the values of one or more variables

CALL TANH Routine
Returns the hyperbolic tangent

CNONCT Function
Returns the noncentrality parameter from a chi-squared distribution

COALESCE Function
Returns the first non-missing value from a list of numeric arguments.

COMB Function
Computes the number of combinations of n elements taken r at a time

CONSTANT Function
Computes some machine and mathematical constants

DAIRY Function
Returns the derivative of the AIRY function

DEVIANCE Function
Computes the deviance

DIGAMMA Function
Returns the value of the Digamma function

ERF Function
Returns the value of the (normal) error function

ERFC Function
Returns the value of the complementary (normal) error function

EXP Function
Returns the value of the exponential function

FACT Function
Computes a factorial

FNONCT Function
Returns the value of the noncentrality parameter of an F distribution

GAMMA Function
Returns the value of the Gamma function

IBESSEL Function
Returns the value of the modified bessel function

JBESSEL Function
Returns the value of the bessel function

LGAMMA Function
Returns the natural logarithm of the Gamma function

LOG Function
Returns the natural (base e) logarithm

LOG10 Function
Returns the logarithm to the base 10

LOG2 Function
Returns the logarithm to the base 2

LOGBETA Function
Returns the logarithm of the beta function

MOD Function
Returns the remainder from the division of the first argument by the
second argument, fuzzed to avoid most unexpected floating-point
results

MODZ Function
Returns the remainder from the division of the first argument by the
second argument, using zero fuzzing

PERM Function
Computes the number of permutations of n items taken r at a time

SIGN Function
Returns the sign of a value

SQRT Function
Returns the square root of a value

TNONCT Function
Returns the value of the noncentrality parameter from the student's t
distribution

TRIGAMMA Function
Returns the value of the Trigamma function
Probability CDF Function
Computes cumulative distribution functions

LOGCDF Function
Computes the logarithm of a left cumulative distribution function

LOGPDF Function
Computes the logarithm of a probability density (mass) function

LOGSDF Function
Computes the logarithm of a survival function

PDF Function
Computes probability density (mass) functions

POISSON Function
Returns the probability from a Poisson distribution

PROBBETA Function
Returns the probability from a beta distribution

PROBBNML Function
Returns the probability from a binomial distribution

PROBBNRM Function
Computes a probability from the bivariate normal distribution

PROBCHI Function
Returns the probability from a chi-squared distribution

PROBF Function
Returns the probability from an F distribution

PROBGAM Function
Returns the probability from a gamma distribution

PROBHYPR Function
Returns the probability from a hypergeometric distribution

PROBMC Function
Computes a probability or a quantile from various distributions for
multiple comparisons of means

PROBNEGB Function
Returns the probability from a negative binomial distribution

PROBNORM Function
Returns the probability from the standard normal distribution

PROBT Function
Returns the probability from a t distribution

SDF Function
Computes a survival function
Quantile BETAINV Function
Returns a quantile from the beta distribution

CINV Function
Returns a quantile from the chi-squared distribution

FINV Function
Returns a quantile from the F distribution

GAMINV Function
Returns a quantile from the gamma distribution

PROBIT Function
Returns a quantile from the standard normal distribution

QUANTILE Function
Computes the quantile from a specified distribution

TINV Function
Returns a quantile from the t distribution
Random Number CALL RANBIN Routine
Returns a random variate from a binomial distribution

CALL RANCAU Routine
Returns a random variate from a Cauchy distribution

CALL RANEXP Routine
Returns a random variate from an exponential distribution

CALL RANGAM Routine
Returns a random variate from a gamma distribution

CALL RANNOR Routine
Returns a random variate from a normal distribution

CALL RANPERK Routine
Randomly permutes the values of the arguments, and returns a
permutation of k out of n values

CALL RANPERM Routine
Randomly permutes the values of the arguments

CALL RANPOI Routine
Returns a random variate from a Poisson distribution

CALL RANTBL Routine
Returns a random variate from a tabled probability distribution

CALL RANTRI Routine
Returns a random variate from a triangular distribution

CALL RANUNI Routine
Returns a random variate from a uniform distribution

CALL STREAMINIT Routine
Specifies a seed value to use for subsequent random number generation
by the RAND function

NORMAL Function
Returns a random variate from a normal distribution

RANBIN Function
Returns a random variate from a binomial distribution

RANCAU Function
Returns a random variate from a Cauchy distribution

RAND Function
Generates random numbers from a specified distribution

RANEXP Function
Returns a random variate from an exponential distribution

RANGAM Function
Returns a random variate from a gamma distribution

RANNOR Function
Returns a random variate from a normal distribution

RANPOI Function
Returns a random variate from a Poisson distribution

RANTBL Function
Returns a random variate from a tabled probability distribution

RANTRI Function
Returns a random variate from a triangular distribution

RANUNI Function
Returns a random variate from a uniform distribution

UNIFORM Function
Returns a random variate from a uniform distribution
SAS File I/O ATTRC Function
Returns the value of a character attribute for a SAS data set

ATTRN Function
Returns the value of a numeric attribute for the specified SAS data set

CEXIST Function
Verifies the existence of a SAS catalog or SAS catalog entry

CLOSE Function
Closes a SAS data set

CUROBS Function
Returns the observation number of the current observation

DROPNOTE Function
Deletes a note marker from a SAS data set or an external file

DSNAME Function
Returns the SAS data set name that is associated with a data set identifier

EXIST Function
Verifies the existence of a SAS data library member

FETCH Function
Reads the next nondeleted observation from a SAS data set into the
Data Set Data Vector (DDV)

FETCHOBS Function
Reads a specified observation from a SAS data set into the Data Set
Data Vector (DDV)

GETVARC Function
Returns the value of a SAS data set character variable

GETVARN Function
Returns the value of a SAS data set numeric variable

IORCMSG Function
Returns a formatted error message for _IORC_

LIBNAME Function
Assigns or deassigns a libref for a SAS data library

LIBREF Function
Verifies that a libref has been assigned

NOTE Function
Returns an observation ID for the current observation of a SAS data set

OPEN Function
Opens a SAS data set

PATHNAME Function
Returns the physical name of a SAS data library or of an external
file, or returns a blank

POINT Function
Locates an observation identified by the NOTE function

REWIND Function
Positions the data set pointer at the beginning of a SAS data set

SYSMSG Function
Returns the text of error messages or warning messages from the last
data set or external file function execution

SYSRC Function
Returns a system error number

VARFMT Function
Returns the format assigned to a SAS data set variable

VARINFMT Function
Returns the informat assigned to a SAS data set variable

VARLABEL Function
Returns the label assigned to a SAS data set variable

VARLEN Function
Returns the length of a SAS data set variable

VARNAME Function
Returns the name of a SAS data set variable

VARNUM Function
Returns the number of a variable's position in a SAS data set

VARTYPE Function
Returns the data type of a SAS data set variable
Special ADDR Function
Returns the memory address of a numeric variable on a 32-bit platform

ADDRLONG Function
Returns the memory address of a character variable on 32-bit and
64-bit platforms

CALL POKE Routine
Writes a value directly into memory on a 32-bit platform

CALL POKELONG Routine
Writes a value directly into memory on 32-bit and 64-bit platforms

CALL SLEEP Routine
Suspends the execution of a program that invokes this call routine
for a specified period of time

CALL SYSTEM Routine
Submits an operating environment command for execution

DIF Function
Returns differences between the argument and its nth lag

GETOPTION Function
Returns the value of a SAS system or graphics option

INPUT Function
Returns the value produced when a SAS expression that uses a
specified informat expression is read

INPUTC Function
Enables you to specify a character informat at run time

INPUTN Function
Enables you to specify a numeric informat at run time

LAG Function
Returns values from a queue

PEEK Function
Stores the contents of a memory address into a numeric variable on a
32-bit platform

PEEKC Function
Stores the contents of a memory address in a character variable on a
32-bit platform

PEEKCLONG Function
Stores the contents of a memory address in a character variable on
32-bit and 64-bit platforms

PEEKLONG Function
Stores the contents of a memory address in a numeric variable on
32-bit and 64-bit platforms

PTRLONGADD Function
Returns the pointer address as a character variable on 32-bit and
64-bit platforms

PUT Function
Returns a value using a specified format

PUTC Function
Enables you to specify a character format at run time

PUTN Function
Enables you to specify a numeric format at run time

SLEEP Function
Suspends the execution of a program that invokes this function for a
specified period of time

SYSGET Function
Returns the value of the specified operating environment variable

SYSPARM Function
Returns the system parameter string

SYSPROCESSID Function
Returns the process id of the current process

SYSPROCESSNAME Function
Returns the process name associated with a given process id or the
name of the current process

SYSPROD Function
Determines if a product is licensed

SYSTEM Function
Issues an operating environment command during a SAS session and
returns the system return code

UUIDGEN Function
Returns the short or binary form of a Universal Unique Identifier (UUID)
State and ZIP Code FIPNAME Function
Converts two-digit FIPS codes to uppercase state names

FIPNAMEL Function
Converts two-digit FIPS codes to mixed case state names

FIPSTATE Function
Converts two-digit FIPS codes to two-character state postal codes

STFIPS Function
Converts state postal codes to FIPS state codes

STNAME Function
Converts state postal codes to uppercase state names

STNAMEL Function
Converts state postal codes to mixed case state names

ZIPCITY Function
Returns a city name and the two-character postal code that
corresponds to a ZIP code

ZIPFIPS Function
Converts ZIP codes to two-digit FIPS codes

ZIPNAME Function
Converts ZIP codes to uppercase state names

ZIPNAMEL Function
Converts ZIP codes to mixed case state names

ZIPSTATE Function
Converts ZIP codes to two-character state postal codes
Trigonometric ARCOS Function
Returns the arccosine

ARSIN Function
Returns the arcsine

ATAN Function
Returns the arc tangent

ATAN2 Function
Returns the arc tangent of two numeric variables

COS Function
Returns the cosine

SIN Function
Returns the sine

TAN Function
Returns the tangent
Truncation CEIL Function
Returns the smallest integer that is greater than or equal to the
argument, fuzzed to avoid unexpected floating-point results

CEILZ Function
Returns the smallest integer that is greater than or equal to the
argument, using zero fuzzing

FLOOR Function
Returns the largest integer that is less than or equal to the
argument, fuzzed to avoid unexpected floating-point results

FLOORZ Function
Returns the largest integer that is less than or equal to the
argument, using zero fuzzing

FUZZ Function
Returns the nearest integer if the argument is within 1E-12

INT Function
Returns the integer value, fuzzed to avoid unexpected floating-point results

INTZ Function
Returns the integer portion of the argument, using zero fuzzing

ROUND Function
Rounds the first argument to the nearest multiple of the second
argument, or to the nearest integer when the second argument is
omitted

ROUNDE Function
Rounds the first argument to the nearest multiple of the second
argument, and returns an even multiple when the first argument is
halfway between the two nearest multiples

ROUNDZ Function
Rounds the first argument to the nearest multiple of the second
argument, with zero fuzzing

TRUNC Function
Truncates a numeric value to a specified length
Variable Control CALL LABEL Routine
Assigns a variable label to a specified character variable

CALL SET Routine
Links SAS data set variables to DATA step or macro variables that
have the same name and data type

CALL VNAME Routine
Assigns a variable name as the value of a specified variable
Variable Information CALL VNEXT Routine
Returns the name, type, and length of a variable that is used in a DATA step

VARRAY Function
Returns a value that indicates whether the specified name is an array

VARRAYX Function
Returns a value that indicates whether the value of the specified
argument is an array

VARTRANSCODE Function
Returns the transcode attribute of a SAS data set variable

VFORMAT Function
Returns the format that is associated with the specified variable

VFORMATD Function
Returns the format decimal value that is associated with the
specified variable

VFORMATDX Function
Returns the format decimal value that is associated with the value of
the specified argument

VFORMATN Function
Returns the format name that is associated with the specified variable

VFORMATNX Function
Returns the format name that is associated with the value of the
specified argument

VFORMATW Function
Returns the format width that is associated with the specified variable

VFORMATWX Function
Returns the format width that is associated with the value of the
specified argument

VFORMATX Function
Returns the format that is associated with the value of the specified
argument

VINARRAY Function
Returns a value that indicates whether the specified variable is a
member of an array

VINARRAYX Function
Returns a value that indicates whether the value of the specified
argument is a member of an array

VINFORMAT Function
Returns the informat that is associated with the specified variable

VINFORMATD Function
Returns the informat decimal value that is associated with the
specified variable

VINFORMATDX Function
Returns the informat decimal value that is associated with the value
of the specified argument

VINFORMATN Function
Returns the informat name that is associated with the specified variable

VINFORMATNX Function
Returns the informat name that is associated with the value of the
specified argument

VINFORMATW Function
Returns the informat width that is associated with the specified variable

VINFORMATWX Function
Returns the informat width that is associated with the value of the
specified argument

VINFORMATX Function
Returns the informat that is associated with the value of the
specified argument

VLABEL Function
Returns the label that is associated with the specified variable

VLABELX Function
Returns the variable label for the value of the specified argument

VLENGTH Function
Returns the compile-time (allocated) size of the specified variable

VLENGTHX Function
Returns the compile-time (allocated) size for the value of the
specified argument

VNAME Function
Returns the name of the specified variable

VNAMEX Function
Validates the value of the specified argument as a variable name

VTRANSCODE Function
Returns a value that indicates whether transcoding is on or off for
the specified character variable

VTRANSCODEX Function
Returns a value that indicates whether transcoding is on or off for
the specified argument

VTYPE Function
Returns the type (character or numeric) of the specified variable

VTYPEX Function
Returns the type (character or numeric) for the value of the
specified argument

VVALUE Function
Returns the formatted value that is associated with the variable that
you specify

VVALUEX Function
Returns the formatted value that is associated with the argument that
you specify
Web Tools HTMLDECODE Function
Decodes a string containing HTML numeric character references or HTML
character entity references and returns the decoded string

HTMLENCODE Function
Encodes characters using HTML character entity references and returns
the encoded string

URLDECODE Function
Returns a string that was decoded using the URL escape syntax

URLENCODE Function
Returns a string that was encoded using the URL escape syntax





Previous Page | Next Page | Top of Page

Copyright (c) 2006 by SAS Institute Inc., Cary, NC, USA. All rights reserved.
Post by t***@hotpop.com
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Paul M. Dorfman
2006-05-01 21:25:53 UTC
Permalink
Post by Gary McQuown
-----Original Message-----
Sent: Monday, May 01, 2006 4:03 PM
Subject: converting char to num and num to char in datastep
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
Toby,

This is a question answered divers times on sas-l. Look at today's Toby D.'s
reply, for example.
Post by Gary McQuown
So basic, so troublesome - only in SAS.
You are wrong on both counts: Is it not as basic if you try to do it all
yourself, and it is SAS which makes it not troubesome. To understand, you have
to understand how SAS derives all its mileage from two data types only, and why,
because of that, the concept of informats and formats is central to SAS.
Explicit type conversion requires explicit [in]format coding coupled with the
input/put functions.
Post by Gary McQuown
While they SAS provides such specialized functions to convert zip to state and
other useless ones

Which ones do you deem useless? Could you elucidate using an argument different
from "I have never used them"?
Post by Gary McQuown
to me it seems the most basic functions are missing in SAS
Please list the functions your consider basic. Then find whether they are absent
from SAS (for instance, look them up in Joe's reply today) and apply your
definition of "most". Let me assure you, though, that MISSING() function is
definitely not missing from SAS...
Post by Gary McQuown
In addition, listing functions alphabetically in the help file does not
indicate
Post by Gary McQuown
much intelligence behind the SAS system of functions.
Agreed. But then search functions listed by category!
Post by Gary McQuown
every other programming environment, I find such things like
operators, string manipulation functions, methematical
functions, while in SAS its all just thrown into your face.
Admittedly, SAS help does yield some room for improvement, but still, search by
category...

Kind regards
------------
Paul Dorfman
Jax, FL
------------
toby dunn
2006-05-01 21:39:29 UTC
Permalink
Toby ,

What are you trying to do with the following statement:


f8 = input( f8 , $50. ) ;

If the goal is to convert a Numeric to a Character then you are using the
wrong function use the Put Function.

If your goal is to go from a Character to a numeric then you have the right
function but the wrong informat, try using a numeric one.

If you are wanting to change the length of a character variable you are
going about it all wrong. Once the attributes are set for a variable you
can't change them in that step. If you know the length needs to change a
much simplier was in SAS to do this is simply to declare its length at the
beggining of the program.

Data one ;
Length F8 $50 ;
set Foo ;
<SAS Code here>
run ;


Toby Dunn





From: ***@HOTPOP.COM
Reply-To: ***@HOTPOP.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 14:28:38 -0700

Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.

I can instantly replace a variable with another value.
q10hlpicp = 6 - q10hlpicp;

I think its not much different:
f8=input(f8,$50.);
But why does this not work?

Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and input
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Venky Chakravarthy
2006-05-01 22:01:09 UTC
Permalink
Post by t***@hotpop.com
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
It would not be a trivial undertaking for SAS to match the search
capabilities of Google.
Post by t***@hotpop.com
I can instantly replace a variable with another value.
q10hlpicp = 6 - q10hlpicp;
f8=input(f8,$50.);
But why does this not work?
It would, given the right set of circumstances. You have not mentioned what
type your input variable is. The following shows that the syntax is valid
but of course it is completely useless.

243 data _null_ ;
244 x = "150" ;
245 put "Before: " x= ;
246 x = input ( x , $8. ) ;
247 put "After: " x= ;
248 run ;

Before: x=150
After: x=150

My guess is that you are trying to change the variable type within the data
step. It can tricked by renaming the variable in the data step and then
converting the renamed variable to the desired type and storing it under
the old name. There are examples in the archives.

Venky Chakravarthy
Post by t***@hotpop.com
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and
input
Post by t***@hotpop.com
Post by toby dunn
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Choate,
2006-05-02 00:57:50 UTC
Permalink
Here's a typical example of converting a numeric zipcode to an character =
zipcode, but retaining the column name.
=20
Note numeric and character variables are not interchangable, so one =
needs to switch the names:
=20
data stuff(drop=3Dzipn) ;
set stuff (rename=3D(zip=3Dzipn));
zip=3Dput(zipn,z5.);
run;

If all you need to do is change the length of a variable you can do that =
before the set statement. For example to truncate a Zip $9 to a Zip $5:
=20
data stuff;
length zip $5;
set stuff;
run;
=20
=20
hth
=20
Paul Choate
(916) 654-2160
DDS Data Extraction

________________________________

From: SAS(r) Discussion on behalf of ***@HOTPOP.COM
Sent: Mon 5/1/2006 2:28 PM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: converting char to num and num to char in datastep



Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.

I can instantly replace a variable with another value.
q10hlpicp =3D 6 - q10hlpicp;

I think its not much different:
f8=3Dinput(f8,$50.);
But why does this not work?

Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and =
input
Post by toby dunn
to go from character to numeric.
data one ;
Num1 =3D 123 ;
Char1 =3D '987' ;
Num2 =3D input( Char1 , 8. ) ;
Char2 =3D put( Num1 , 8. -L ) ;
Num1Type =3D Vtype( Num1 ) ;
Char1Type =3D Vtype( Char1 ) ;
Num2Type =3D Vtype( Num2 ) ;
Char2Type =3D Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc =
sql)?
Post by toby dunn
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in =
the
Post by toby dunn
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
t***@hotpop.com
2006-05-02 17:54:36 UTC
Permalink
Hi Paul

It does not work this way!?

data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a)); f8=put(f8a,
1 !+z5.); f9=put(f9a, z5.);
--- ---
48 48
NOTE: Line generated by the CALL EXECUTE routine.
2 + f10=put(f10a, z5.); f13=put(f13a, z5.); f0=2; run;
--- ---
48 48

ERROR 48-59: The format $Z was not found or could not be loaded.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Post by Choate,
Here's a typical example of converting a numeric zipcode to an character =
zipcode, but retaining the column name.
=20
Note numeric and character variables are not interchangable, so one =
=20
data stuff(drop=3Dzipn) ;
set stuff (rename=3D(zip=3Dzipn));
zip=3Dput(zipn,z5.);
run;
If all you need to do is change the length of a variable you can do that =
=20
data stuff;
length zip $5;
set stuff;
run;
=20
=20
hth
=20
Paul Choate
(916) 654-2160
DDS Data Extraction
________________________________
Sent: Mon 5/1/2006 2:28 PM
Subject: Re: converting char to num and num to char in datastep
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
I can instantly replace a variable with another value.
q10hlpicp =3D 6 - q10hlpicp;
f8=3Dinput(f8,$50.);
But why does this not work?
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and =
input
Post by toby dunn
to go from character to numeric.
data one ;
Num1 =3D 123 ;
Char1 =3D '987' ;
Num2 =3D input( Char1 , 8. ) ;
Char2 =3D put( Num1 , 8. -L ) ;
Num1Type =3D Vtype( Num1 ) ;
Char1Type =3D Vtype( Char1 ) ;
Num2Type =3D Vtype( Num2 ) ;
Char2Type =3D Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc =
sql)?
Post by toby dunn
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in =
the
Post by toby dunn
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
data _null_;
2006-05-02 18:09:06 UTC
Permalink
Post by t***@hotpop.com
Hi Paul
2 + f10=put(f10a, z5.); f13=put(f13a, z5.); f0=2; run;
--- ---
48 48
ERROR 48-59: The format $Z was not found or could not be loaded.
SAS is telling you that F10A and F13A are character. As in this example.

17 data work.test;
18 x = '1';
19 y = put(x,z5.);
---
48
ERROR 48-59: The format $Z was not found or could not be loaded.



20 run;
toby dunn
2006-05-02 19:02:35 UTC
Permalink
Toby ,

I fail to see why this is even needed.


data x ( drop = __F ) ;
set x ( rename = ( F8 = __F8 F9 = __F9 F10 = __F10 F13 = __F13 ) ) ;

F8 = put( __F8 , 8. -L ) ;
F9 = put( __F9 , 8. -L ) ;
F10 = put( __F10 , 8. -L ) ;
F13 = put( __F13 , 8. -L ) ;

run ;


THe put function only needs to know how to interprete the value specified in
the source statement of the function call. Besides that even if you get the
format for the numeric variable that only specifies how SAS should print
that numeric value not how the put function should interpret it. It still
is just a numeric variable with a length of eight. So all that one need to
use is a standard numeric length of 8 format value which happens to be "8."
.


Toby Dunn

From: ***@HOTPOP.COM
Reply-To: ***@HOTPOP.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: converting char to num and num to char in datastep
Date: Tue, 2 May 2006 10:23:03 -0700

Ok, got it to use the put function. What about if I dont know the format
of the source variable in advance?

I though vformat() returns a format name??? (at least according tot the
onlinedoc, but maybe they are lying there)

Toby


data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a));
1 !+f8=put(f8a,vformat(f8a)); f9=put
-------
85
76
NOTE: Line generated by the CALL EXECUTE routine.
2 +(f9a,vformat(f8a)); f10=put(f10a,vformat(f8a));
f13=put(f13a,vformat(f8a)); f0=2; run;
------- ------- -------
85 85 85
76 76 76

ERROR 85-322: Expecting a format name.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and input
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Gerstle, John (CDC/NCHSTP/DHAP) (CTR)
2006-05-02 18:44:52 UTC
Permalink
Try this:

data x; /*length f8 f9 f10 f13 8.;*/
set x(rename=(f8=f8a f9=f9a f10=f10a f13=f13a));
array f (*)f8 f9 f10 f13;
array fa (*)f8a f9a f10a f13a;
do I = 1 to dim(f);
f(i) = put( (fa(i)/1), z5.);
end;
drop I f8a f9a f10a f13a;
run;

The leading zero format (zx.) doesn't exist for character type (don't
know why not?), and so you need to convert the variable type to numeric
to use it. By dividing each character variable by 1 (could also
multiply by 1), it will cause SAS to implicitly convert character to
numeric. This assumes that you have ONLY numerals as values in these
variables.

The reasoning, I believe, is that SAS composes the PDV from the
variables being read into the data step, at the start of the data step
loop. So if you have F8 to F13 being read as character, then for the
life of the data step, these variables will be character. As you rename
them, this 'frees' up these variable names which would allow the
creation of 'new' variable names F8 to F13, which could be either
numeric or character, depending upon the (first) values to be inputted.
You could use the LENGTH statement, like above, to explicitly state that
these are numeric (there are other ways to do this).

Granted, conversion between numeric and character methods may seem
messy. I've run into the error you've mentioned a few times, and have
wondered why. But it's easily solved with some planning and knowledge of
the way the data step reads in data.

There is a danger of forcing a character variable to convert to numeric:
Loss of data due to some unforeseen values entered into the database.
If a value happens to be '1,230', then, as SAS converts it to numeric,
this value, having the comma, would be converted to '.', a missing
value. With this in mind, the above logic makes some sense and may save
you from this sort of danger, by forcing you to 'jump thru a few more
hoops' to get your variables converted.

John Gerstle, MS
Biostatistician
Northrop Grumman
CDC Information Technological Support Contract (CITS)
NCHSTP \DHAP \HICSB \Research, Analysis, and Evaluation Section
Centers for Disease Control and Prevention

"As far as the laws of mathematics refer to reality, they are not
certain; and as far as they are certain, they do not refer to reality."

Albert Einstein, addressing the Prussian Acadamy of
Science, Berlin , Jan 27, 1921

"Boss. We've got cats." "Meow"
Post by Gary McQuown
-----Original Message-----
Sent: Tuesday, May 02, 2006 1:55 PM
Subject: Re: converting char to num and num to char in datastep
Hi Paul
It does not work this way!?
data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a)); f8=put(f8a,
1 !+z5.); f9=put(f9a, z5.);
--- ---
48 48
NOTE: Line generated by the CALL EXECUTE routine.
2 + f10=put(f10a, z5.); f13=put(f13a, z5.); f0=2; run;
--- ---
48 48
ERROR 48-59: The format $Z was not found or could not be loaded.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was
stopped.
Post by Gary McQuown
real time 0.01 seconds
cpu time 0.01 seconds
Post by Choate,
Here's a typical example of converting a numeric zipcode to an
character =
Post by Choate,
zipcode, but retaining the column name.
=20
Note numeric and character variables are not interchangable, so one
=
Post by Gary McQuown
Post by Choate,
=20
data stuff(drop=3Dzipn) ;
set stuff (rename=3D(zip=3Dzipn));
zip=3Dput(zipn,z5.);
run;
If all you need to do is change the length of a variable you can do
that =
Post by Choate,
before the set statement. For example to truncate a Zip $9 to a
Zip
Post by Gary McQuown
Post by Choate,
=20
data stuff;
length zip $5;
set stuff;
run;
=20
=20
hth
=20
Paul Choate
(916) 654-2160
DDS Data Extraction
________________________________
Sent: Mon 5/1/2006 2:28 PM
Subject: Re: converting char to num and num to char in datastep
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
I can instantly replace a variable with another value.
q10hlpicp =3D 6 - q10hlpicp;
f8=3Dinput(f8,$50.);
But why does this not work?
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character
and =
Post by Gary McQuown
Post by Choate,
input
Post by toby dunn
to go from character to numeric.
data one ;
Num1 =3D 123 ;
Char1 =3D '987' ;
Num2 =3D input( Char1 , 8. ) ;
Char2 =3D put( Num1 , 8. -L ) ;
Num1Type =3D Vtype( Num1 ) ;
Char1Type =3D Vtype( Char1 ) ;
Num2Type =3D Vtype( Num2 ) ;
Char2Type =3D Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc
=
Post by Gary McQuown
Post by Choate,
sql)?
Post by toby dunn
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip
to
Post by Gary McQuown
Post by Choate,
Post by toby dunn
state and other useless ones, to me it seems the most basic
functions
Post by Gary McQuown
Post by Choate,
Post by toby dunn
are missing in SAS. In addition, listing functions alphabetically
in =
Post by Gary McQuown
Post by Choate,
the
Post by toby dunn
help file does not indicate much intelligence behind the SAS system
of
Post by Gary McQuown
Post by Choate,
Post by toby dunn
functions. In every other programming environment, I find such
things
Post by Gary McQuown
Post by Choate,
Post by toby dunn
like operators, string manipulation functions, methematical
functions,
Post by Gary McQuown
Post by Choate,
Post by toby dunn
while in SAS its all just thrown into your face.
toby dunn
2006-05-02 18:34:35 UTC
Permalink
Toby ,

Put statements use formats and certain formats are for certain types of
variables. The Zw.d format is for numeric data.

So to do what you are asking requires you first change the character value
to a numeric first and then back to a character with the put and the right
format.

data one ;

Num1 = 123 ;
Num2 = '123' ;

Char1 = put( Num1 , z5. ) ;
Char2 = put( input(Num2 , 8. ) , z5. ) ;


put _all_ ;
run ;




Toby Dunn





From: ***@HOTPOP.COM
Reply-To: ***@HOTPOP.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: converting char to num and num to char in datastep
Date: Tue, 2 May 2006 10:54:36 -0700

Hi Paul

It does not work this way!?

data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a)); f8=put(f8a,
1 !+z5.); f9=put(f9a, z5.);
--- ---
48 48
NOTE: Line generated by the CALL EXECUTE routine.
2 + f10=put(f10a, z5.); f13=put(f13a, z5.); f0=2; run;
--- ---
48 48

ERROR 48-59: The format $Z was not found or could not be loaded.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Post by Choate,
Here's a typical example of converting a numeric zipcode to an character =
zipcode, but retaining the column name.
=20
Note numeric and character variables are not interchangable, so one =
=20
data stuff(drop=3Dzipn) ;
set stuff (rename=3D(zip=3Dzipn));
zip=3Dput(zipn,z5.);
run;
If all you need to do is change the length of a variable you can do that =
=20
data stuff;
length zip $5;
set stuff;
run;
=20
=20
hth
=20
Paul Choate
(916) 654-2160
DDS Data Extraction
________________________________
Sent: Mon 5/1/2006 2:28 PM
Subject: Re: converting char to num and num to char in datastep
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
I can instantly replace a variable with another value.
q10hlpicp =3D 6 - q10hlpicp;
f8=3Dinput(f8,$50.);
But why does this not work?
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and =
input
Post by toby dunn
to go from character to numeric.
data one ;
Num1 =3D 123 ;
Char1 =3D '987' ;
Num2 =3D input( Char1 , 8. ) ;
Char2 =3D put( Num1 , 8. -L ) ;
Num1Type =3D Vtype( Num1 ) ;
Char1Type =3D Vtype( Char1 ) ;
Num2Type =3D Vtype( Num2 ) ;
Char2Type =3D Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc =
sql)?
Post by toby dunn
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in =
the
Post by toby dunn
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Choate,
2006-05-02 19:09:04 UTC
Permalink
Toby -=20

Variable type is probably the most fundamental information you need to
know for whatever you do in SAS. In some cases SAS will allow you to
use numeric functions by implicitly converting character to numeric, but
in general you must know whether a variable is character or numeric.

It is very important because, for example, a numeric digit 5 and a
string digit 5 are stored and processed differently. Missing values are
also conceptually very different in the two contexts. Also, character
set ordering is platform dependent whereas numeric ordering is not.=20

Use proc contents, dictionary tables, vartype function, open the dataset
in the viewer, etc. to find out how your variables are defined.

You need to understand things like
1. SAS defaults to numeric
2. The Put statement always produces character strings, acting on
character or numeric values with associated character or numeric formats
3. Input statements always read character strings and produce
either character or numeric values as defined by the informat
4. Generally an arithmetic operation or function on a numeric value
stored as text will cause an implicit text to numeric conversion, but
certain situations, like where clause processing, can produce unexpected
results.
=20
Note you can convert between variable types with put and input
functions, and you may even nest the functions if needed to convert in
place character=3D>numeric=3D>character or =
numeric=3D>character=3D>numeric, but
as you know a variable type may not itself be converted in place. =20

Seems to me you might benefit by reading here a bit:

Variables
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000998827.htm
Missing Values
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a001292604.htm
Expressions
http://support.sas.com/onlinedoc/913/getDoc/en/lrcon.hlp/a000998770.htm


Hope that helps -=20

Paul Choate
DDS Data Extraction
(916) 654-2160
Post by Gary McQuown
-----Original Message-----
Sent: Tuesday, May 02, 2006 10:55 AM
Subject: Re: converting char to num and num to char in datastep
=20
Hi Paul
=20
It does not work this way!?
=20
data x(drop=3Df8a f9a f10a f13a); set x(rename=3D(f8=3Df8a f9=3Df9a =
f10=3Df10a
Post by Gary McQuown
f13=3Df13a)); f8=3Dput(f8a,
1 !+z5.); f9=3Dput(f9a, z5.);
--- ---
48 48
NOTE: Line generated by the CALL EXECUTE routine.
2 + f10=3Dput(f10a, z5.); f13=3Dput(f13a, z5.); f0=3D2; run;
--- ---
48 48
=20
ERROR 48-59: The format $Z was not found or could not be loaded.
=20
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was
stopped.
Post by Gary McQuown
real time 0.01 seconds
cpu time 0.01 seconds
=20
=20
=20
=20
Post by Choate,
Here's a typical example of converting a numeric zipcode to an
character
Post by Gary McQuown
=3D
Post by Choate,
zipcode, but retaining the column name.
=3D20
Note numeric and character variables are not interchangable, so one
=3D
Post by Gary McQuown
Post by Choate,
=3D20
data stuff(drop=3D3Dzipn) ;
set stuff (rename=3D3D(zip=3D3Dzipn));
zip=3D3Dput(zipn,z5.);
run;
If all you need to do is change the length of a variable you can do
that
Post by Gary McQuown
=3D
Post by Choate,
before the set statement. For example to truncate a Zip $9 to a Zip
=3D20
data stuff;
length zip $5;
set stuff;
run;
=3D20
=3D20
hth
=3D20
Paul Choate
(916) 654-2160
DDS Data Extraction
________________________________
Sent: Mon 5/1/2006 2:28 PM
Subject: Re: converting char to num and num to char in datastep
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
I can instantly replace a variable with another value.
q10hlpicp =3D3D 6 - q10hlpicp;
f8=3D3Dinput(f8,$50.);
But why does this not work?
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character
and =3D
Post by Gary McQuown
Post by Choate,
input
Post by toby dunn
to go from character to numeric.
data one ;
Num1 =3D3D 123 ;
Char1 =3D3D '987' ;
Num2 =3D3D input( Char1 , 8. ) ;
Char2 =3D3D put( Num1 , 8. -L ) ;
Num1Type =3D3D Vtype( Num1 ) ;
Char1Type =3D3D Vtype( Char1 ) ;
Num2Type =3D3D Vtype( Num2 ) ;
Char2Type =3D3D Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc =
=3D
Post by Gary McQuown
Post by Choate,
sql)?
Post by toby dunn
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic
functions
Post by Gary McQuown
Post by Choate,
Post by toby dunn
are missing in SAS. In addition, listing functions alphabetically in
=3D
Post by Gary McQuown
Post by Choate,
the
Post by toby dunn
help file does not indicate much intelligence behind the SAS system
of
Post by Gary McQuown
Post by Choate,
Post by toby dunn
functions. In every other programming environment, I find such
things
Post by Gary McQuown
Post by Choate,
Post by toby dunn
like operators, string manipulation functions, methematical
functions,
Post by Gary McQuown
Post by Choate,
Post by toby dunn
while in SAS its all just thrown into your face.
Howard Schreier <hs AT dc-sug DOT org>
2006-05-03 15:52:16 UTC
Permalink
Post by t***@hotpop.com
Thanks. Found it by now via google. Makes one think why I find the
functions via google but not using online help.
I can instantly replace a variable with another value.
q10hlpicp = 6 - q10hlpicp;
Use terminology carefully: here you replace the *value* of a variable with
another *value*.
Post by t***@hotpop.com
f8=input(f8,$50.);
But why does this not work?
As has been shown, this does work if F8 is a character variable.

I think you meant to ask about something like this:

f8 = '123';
f8 = input(f8,3.);

F8 is of character type and cannot be changed on the fly.

PROC SQL is a little different. You can code

create table converted as select input(f8,3.) as f8 from whatever;

where F8 is character in WHATEVER and numeric in CONVERTED. The 2 columns
coexist, as demonstrated in

data whatever;
f8 = '123';
run;

proc sql;
create table converted as
select input(f8,3.) + 0.5 as f8,
input(whatever.f8,2.) + calculated f8 as sum
from whatever;
quit;

SUM receives the value 135.5 (123+0.5+12).
Post by t***@hotpop.com
Toby
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and
input
Post by t***@hotpop.com
Post by toby dunn
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Howard Schreier <hs AT dc-sug DOT org>
2006-05-03 15:56:20 UTC
Permalink
Post by t***@hotpop.com
Ok, got it to use the put function. What about if I dont know the format
of the source variable in advance?
I though vformat() returns a format name??? (at least according tot the
onlinedoc, but maybe they are lying there)
The PUT/INPUT functions require that the format/informat be specified at
compile time. If you want to use an expression (such as a VFORMAT call) for
the second argument, you must use the PUTN or PUTC or INPUTN or INPUTC
function instead.
Post by t***@hotpop.com
Toby
data x(drop=f8a f9a f10a f13a); set x(rename=(f8=f8a f9=f9a f10=f10a
f13=f13a));
1 !+f8=put(f8a,vformat(f8a)); f9=put
-------
85
76
NOTE: Line generated by the CALL EXECUTE routine.
2 +(f9a,vformat(f8a)); f10=put(f10a,vformat(f8a));
f13=put(f13a,vformat(f8a)); f0=2; run;
------- ------- -------
85 85 85
76 76 76
ERROR 85-322: Expecting a format name.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X may be incomplete. When this step was
stopped there were 0
observations and 14 variables.
WARNING: Data set WORK.X was not replaced because this step was stopped.
real time 0.01 seconds
cpu time 0.01 seconds
Post by toby dunn
Toby ,
It is simple use the put function to go from numeric to character and
input
Post by t***@hotpop.com
Post by toby dunn
to go from character to numeric.
data one ;
Num1 = 123 ;
Char1 = '987' ;
Num2 = input( Char1 , 8. ) ;
Char2 = put( Num1 , 8. -L ) ;
Num1Type = Vtype( Num1 ) ;
Char1Type = Vtype( Char1 ) ;
Num2Type = Vtype( Num2 ) ;
Char2Type = Vtype( Char2 ) ;
put _all_ ;
run ;
Toby Dunn
Subject: converting char to num and num to char in datastep
Date: Mon, 1 May 2006 13:03:20 -0700
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
t***@hotpop.com
2006-05-03 19:49:50 UTC
Permalink
Hi All

Any simplification suggestions?

Regarding the put, although I did not read all responses yet, I give up
temporarily on if the format argument in the put function is that format
of the source argument or the desired format of the return value of the
function (specifying either one, neither worked previously)


%macro h (h);
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='MD'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a $50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8; f9a=f9;
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=2;
run;
proc append base=y data=x(firstobs=2) force;
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='Sr Mgr'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a $50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8; f9a=f9;
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=1;
run;
proc append base=y data=x(firstobs=2) force;
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='Staff'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a $50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8; f9a=f9;
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=3;
run;
proc append base=y data=x(firstobs=2) force;
run;
%mend;
Post by t***@hotpop.com
Hi All
How can I convert char to num and num to char in datastep (in proc sql)?
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic functions
are missing in SAS. In addition, listing functions alphabetically in the
help file does not indicate much intelligence behind the SAS system of
functions. In every other programming environment, I find such things
like operators, string manipulation functions, methematical functions,
while in SAS its all just thrown into your face.
Choate,
2006-05-03 20:29:25 UTC
Permalink
Toby - a couple come to mind...

Only a single length statement is necessary:
length f1a 3 f3a f4a f5a f6a f12a f13a $50
f2a f7a f8a f9a f10a f11a $100 ;

Name your new variables fa1, fa2, ... fa13 and then you'll be able to
use list notation like fa1-fa13 in drop and keep statements as well as
elsewhere. In v9 you can rename variables using lists.

Thus your datastep like this:

data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3;
length f2a $100;
length f3a $50;
length f4a $50;
length f5a $50;
length f6a $50;
length f7a $100;
length f8a $100;
length f9a $100;
length f10a $100;
length f11a $100;
length f12a $50;
length f13a $50;
f1a=f1;
f2a=f2;
f3a=f3;
f4a=f4;
f5a=f5;
f6a=f6;
f7a=f7;
f8a=f8;
f9a=f9;
f10a=f10;
f11a=f11;
f12a=f12;
f13a=f13;
f14a=1;
run;

Could be rewritten:

data x;
retain fa1-fa13; *order the PDV;
*assign widths before set statement;
length fa1 3 fa3-fa6 fa12 fa13 $50
fa2 fa7-fa11 $100 ;
set x (rename=(f1-f13=fa1-fa13);
f14a=1;
run;


If you have v913 and SAS/Access for PC Files then you might be able to
achieve your multiple imports and appends with a single datastep using
the excel libname engine.

hth

Paul Choate
DDS Data Extraction
(916) 654-2160
Post by Gary McQuown
-----Original Message-----
Sent: Wednesday, May 03, 2006 12:50 PM
Subject: Re: converting char to num and num to char in datastep
Hi All
Any simplification suggestions?
Regarding the put, although I did not read all responses yet, I give
up
Post by Gary McQuown
temporarily on if the format argument in the put function is that
format
Post by Gary McQuown
of the source argument or the desired format of the return value of
the
Post by Gary McQuown
function (specifying either one, neither worked previously)
%macro h (h);
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='MD'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a
$50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8;
f9a=f9;
Post by Gary McQuown
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=2;
run;
proc append base=y data=x(firstobs=2) force;
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='Sr Mgr'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a
$50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8;
f9a=f9;
Post by Gary McQuown
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=1;
run;
proc append base=y data=x(firstobs=2) force;
proc import datafile="c:\project\ps\data\&h" out=x dbms=excel replace;
sheet='Staff'; getnames=no; dbsaslabel=none; mixed=yes; run;
data x(drop=f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13);
set x;
length f1a 3; length f2a $100; length f3a $50; length f4a $50; length
f5a $50; length f6a $50; length f7a $100; length f8a $100; length f9a
$100; length f10a $100; length f11a $100; length f12a $50; length f13a
$50;
f1a=f1; f2a=f2; f3a=f3; f4a=f4; f5a=f5; f6a=f6; f7a=f7; f8a=f8;
f9a=f9;
Post by Gary McQuown
f10a=f10; f11a=f11; f12a=f12; f13a=f13; f14a=3;
run;
proc append base=y data=x(firstobs=2) force;
run;
%mend;
Post by t***@hotpop.com
Hi All
How can I convert char to num and num to char in datastep (in proc
sql)?
Post by Gary McQuown
Post by t***@hotpop.com
So basic, so troublesome - only in SAS.
Toby
While they SAS provides such specialized functions to convert zip to
state and other useless ones, to me it seems the most basic
functions
Post by Gary McQuown
Post by t***@hotpop.com
are missing in SAS. In addition, listing functions alphabetically in
the
Post by Gary McQuown
Post by t***@hotpop.com
help file does not indicate much intelligence behind the SAS system
of
Post by Gary McQuown
Post by t***@hotpop.com
functions. In every other programming environment, I find such
things
Post by Gary McQuown
Post by t***@hotpop.com
like operators, string manipulation functions, methematical
functions,
Post by Gary McQuown
Post by t***@hotpop.com
while in SAS its all just thrown into your face.
Loading...