BookmarkSubscribeRSS Feed
arunrami
Pyrite | Level 9

HI All, 

 

Here is my scenario - I am using proc import , which will set the datatype based on its content , hence I have taken a copy of dataset using 'set' and tried to convert the datatype using only if it satisfies my 'if logic', but it seems still goes in to the if condition even though it doesn't satisfy my condition .

 

Below sample code , please help out how can I fix this . 

 

Note: variable inside if not supposed to be created as it doesn't pass the criteria ..

 

data A;
infile cards dlm=',' missover;
input name : $32. age $ ;
cards;
hawking ,20
einstein , 40
carl sagan , 30
;
run;

data dummy;
set A;
if vtype(age) = 'N' then do ;
age_1 =  input(age,best.) ;
end;
run;
4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @arunrami 

 

I suggest that you use conditional processing with %if %then %end because the type is not a function at the "row" level but a metadata

 

proc sql noprint;
	select upcase(type) into: type_age trimmed from dictionary.columns
	where libname='WORK' and memname = 'A' and name='age';
quit;

%if "&type_age"="NUM" %then %do ;
	data dummy;
		set A;
		age_1 =  input(age,best.) ;
	run;
%end;

 

arunrami
Pyrite | Level 9
It was just for an example , age is already a char variable , hence my point is , it should not enter in to if logic as it is not satisfying the logic if vtype() = 'N'.

But still its creating variable declared in side if - do..?I wanna know why is it and how PDV works in this case?

*I am using csv file as input
ballardw
Super User

@arunrami wrote:

HI All, 

 

Here is my scenario - I am using proc import , which will set the datatype based on its content , hence I have taken a copy of dataset using 'set' and tried to convert the datatype using only if it satisfies my 'if logic', but it seems still goes in to the if condition even though it doesn't satisfy my condition .

 


Reliance on Proc import, especially if reading data sources that are text such as CSV, is a poor practice. If you know you are going  be reading same structured data, which is sort of implied by fixing specific named variables, then better is to read them correctly in the first place using a data step. Then you control the value types at the beginning.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1136 views
  • 1 like
  • 4 in conversation