|
hi ... if I interpret the question correctly, you just want a function that
will produce a character variable whether the argument is character or numeric
your original job wanted a variable named VALUE with a length of 80
how about using one of the CAT functions
this uses both a NUMERIC (height) and a CHARACTER (sex) variable
proc sql;
create table x as
select name, catt(height) as v1 length=80, catt(sex) as v2 length=80
from sashelp.class;
quit;
proc contents data=x;
ods select variables;
run;
Alphabetic List of Variables and Attributes
# Variable Type Len
1 Name Char 8
2 v1 Char 80
3 v2 Char 80
so, can you try ... SELECT ID, catt(&var) as value length=80
--
Mike Zdeb
U@Albany School of Public Health
One University Place (Room 119)
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
>
> 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"
>>>>
>>>> ;
>>>>
>>>
>>>
>
|