Date: Mon, 5 Apr 2010 23:36:26 -0500
Reply-To: Craig Johnson <cjohns38@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Craig Johnson <cjohns38@GMAIL.COM>
Subject: Re: Inserting Character and Numeric Values into a Single
Character Column
In-Reply-To: <w2zb7a7fa631004051524r93c9d55p8b052d20302353b7@mail.gmail.com>
Content-Type: text/plain; charset=windows-1252
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"
>>
>> ;
>>
>
>
|