DATA Step, Macro, Functions and more

a puzzle when using input to convert character variable to numeric: two steps okay, one step not

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

a puzzle when using input to convert character variable to numeric: two steps okay, one step not

data supptrir (keep= qval qnam idvarval trseq);
set sdtm.supptrir;
where qnam='REVPER' and qval='Review 1';
trseq=input(idvarval,best.);
run;

above code should work (tested on another dataset), but for the current dataset it does not work. I got:

Capture.PNG

 

Idvarval length is 50. I tried both strip(idvarval) and compress(idvarval) in the input statement, also 8., ??best. etc but never worked. However, when I do it in two steps, it works:

data supptrir (keep=usubjid qval qnam idvarval);
set sdtm.supptrir;
where qnam='REVPER' and qval='Review 1';
run;
data supptrir; 
set supptrir ;
trseq=input(idvarval,best.);
run;

 

what could be the reason? very strange. 

 


Accepted Solutions
Solution
‎02-14-2017 07:11 PM
Super User
Posts: 5,099

Re: a puzzle when using input to convert character variable to numeric: two steps okay, one step not

Here's a possibility.

 

Perhaps TRSEQ is already part of SDTM.SUPPTRIR, and has a format connected with it such as 3.1.  In that case, the format isn't wide enough to display the results you are getting.  But the extra DATA step drops the existing TRSEQ (and its accompanying interfering format).

View solution in original post


All Replies
Trusted Advisor
Posts: 1,410

Re: a puzzle when using input to convert character variable to numeric: two steps okay, one step not

[ Edited ]

Enter in your 1st step the line:

      put IDVARVAL $hex8. ;

And check - are the trailing characters after the ID number are realy spaces ('20'x in ascii ) ?

 

You can also do:

    textID = translate(IDVARVAL, '#',' ');

    put textID=

Do you see in log lines like:  10##### or still 10 

 

Use the hex value in compress function.

Super User
Posts: 10,552

Re: a puzzle when using input to convert character variable to numeric: two steps okay, one step not

Since PICTURES do not convey actual data VALUES show us your actual data. https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Solution
‎02-14-2017 07:11 PM
Super User
Posts: 5,099

Re: a puzzle when using input to convert character variable to numeric: two steps okay, one step not

Here's a possibility.

 

Perhaps TRSEQ is already part of SDTM.SUPPTRIR, and has a format connected with it such as 3.1.  In that case, the format isn't wide enough to display the results you are getting.  But the extra DATA step drops the existing TRSEQ (and its accompanying interfering format).

Super Contributor
Posts: 312

Re: a puzzle when using input to convert character variable to numeric: two steps okay, one step not

Yes, this is the reason. There was already a TRSEQ variable, although it is all blank values. I should have checked that. Thanks for your hints. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 139 views
  • 0 likes
  • 4 in conversation