|
Hi Craig,
Instead of referencing ID you should refer to e.g. PUT(ID,2.)
See your docs on the PUT statement (with numerical values).
On the other hand I always advice against using numeric ID values, because
1. they don't have any numeric meaning, they're just a code name (007);
2. in an ID value leading zeros may be significant or required (007);
3. ID values don't necessarily need to be digits only (M);
4. comparing numeric values may need fuzzy math, char values don't.
I always recommend character ID values, even if only digits.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
http://jim.groeneveld.eu.tf
On Mon, 5 Apr 2010 23:36:26 -0500, Craig Johnson <cjohns38@GMAIL.COM> wrote:
>I looked at the put statement and couldn't figure out a way to get it work
>short of reading in the format of the variable every time and including that
>into a macro. As an example, the code below is a stripped down version of
>what I'm doing just for a character variable. Is there a way I could change
>this so it would work for either numeric or character?
>
>/*Example File*/
>
>data Actual;
>infile datalines dsd;
>input ID Char1 $ Num1;
>datalines;
>1, "A",.
>2, .,10
>;
>
>%MACRO TEST (VARS=, WHEREs=);
>data Errors;
>set _Null_;
>attrib ID length=8 format=Best12.;
>attrib Value length=$80;
>run;
>
>%LET i=1;
>%let WHERE=%SCAN(&WHERES, &I);
>%let Var=%Scan(&Vars, &I);
>%do %while (&VAR NE);
>
>PROC SQL;
>INSERT INTO ERRORS (ID, Value)
>SELECT ID, &var as value /*I realize I'd have to use the put statement here
>but the best8 may only be one variable while another is a char and another
>best12. I want something that could handle them all......if that's
>possible*/
>FROM Actual
>WHERE &var = "&where";
>quit;
>
>%let i = %eval(&i+1);
>%let Var=%Scan(Vars, &I);
>%let WHERE=%SCAN(WHERES, &I);
>%end;
>%mend test;
>
>
>%TEST (VARS=char1, WHEREs = A);
>
>On Mon, Apr 5, 2010 at 5:24 PM, Joe Matise <snoopy369@gmail.com> wrote:
>
>> I think if you use PUT() you can force it very simply...
>> insert into errors (id, value)
>> select id, put(variable, best8.) as value from actual where whatever;
>>
>> and if you need multiple variables of course just use union all...
>>
>> -Joe
>>
>>
>> On Mon, Apr 5, 2010 at 3:25 PM, Craig Johnson <cjohns38@gmail.com> wrote:
>>
>>> I created a macro that loops through variables, looks for values out of
>>> range, and then inserts the errors into an error log. I would like to
>>> insert
>>> the values that it finds into a character variable in the error log. Is
>>> there a single generic way I could insert the values into the character
>>> variable if it is coming from a numeric or a character field using proc
>>> sql?
>>>
>>>
>>>
>>>
>>> SO���
>>>
>>> PROC SQL;
>>>
>>> INSERT INTO Errors (ID, Value)
>>>
>>> SELECT ID, WHATEVERVARIABLE AS VALUE format=8 /*will handle numeric or
>>> character values*/
>>>
>>> FROM ACTUAL;
>>>
>>> WHERE whatever=whatever;
>>>
>>> Quit;
>>>
>>>
>>>
>>> /*Example File*/
>>>
>>> *data* Actual;
>>>
>>> infile datalines dsd;
>>>
>>> input ID Char1 $ Num1;
>>>
>>> datalines;
>>>
>>> 1, "A",.
>>>
>>> 2, .,10
>>>
>>> ;
>>>
>>>
>>>
>>> /*What I would like*/
>>>
>>> *data* wanted;
>>>
>>> infile datalines dsd;
>>>
>>> input ID Value $;
>>>
>>> datalines;
>>>
>>> 1, "A"
>>>
>>> 2, "10"
>>>
>>> ;
>>>
>>
>>
|