DATA Step, Macro, Functions and more

Newbie: Help me understand what's wrong

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Newbie: Help me understand what's wrong

 

data money;
infile datalines dlm='@';
input Name $ Salary DOLLAR12.2 Bonus DOLLAR12.2 Age;
datalines;
Harry@$50,000.00@$3,500.00@45
Larry@$30,000.00@$10,500.00@55
Jerry@$1,000,000.00@$100,500.00@21
;

proc print data = money;
run;
proc contents data=money;
run;

So I was running the above code and was expecting the '@' symbol to act as a delimiter, however that doesn't seem to be the case. Can someone help me UNDERSTAND what's wrong? Just to note, I'm just experimenting with SAS to get better at it. The output I get is below: 

Obs	Name	Salary	Bonus	Age
1	Harry	.	.	.
2	Larry	.	.	.
3	Jerry	1000000	.	0

Thanks much!!


Accepted Solutions
Solution
‎12-17-2015 11:06 PM
Respected Advisor
Posts: 4,935

Re: Newbie: Help me understand what's wrong

[ Edited ]

All you need is mixed input style

 

data money;
infile datalines dlm='@';
input Name $ Salary :DOLLAR12.2 Bonus :DOLLAR12.2 Age;
datalines;
Harry@$50,000.00@$3,500.00@45
Larry@$30,000.00@$10,500.00@55
Jerry@$1,000,000.00@$100,500.00@21
;

proc print data = money;
run;

when you prefix the informat with colon, the character field is extracted before the informat is applied.

PG

View solution in original post


All Replies
Solution
‎12-17-2015 11:06 PM
Respected Advisor
Posts: 4,935

Re: Newbie: Help me understand what's wrong

[ Edited ]

All you need is mixed input style

 

data money;
infile datalines dlm='@';
input Name $ Salary :DOLLAR12.2 Bonus :DOLLAR12.2 Age;
datalines;
Harry@$50,000.00@$3,500.00@45
Larry@$30,000.00@$10,500.00@55
Jerry@$1,000,000.00@$100,500.00@21
;

proc print data = money;
run;

when you prefix the informat with colon, the character field is extracted before the informat is applied.

PG
Contributor
Posts: 24

Re: Newbie: Help me understand what's wrong

Oh! Thanks! It's working as expected now.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 167 views
  • 0 likes
  • 2 in conversation