guys ...
stuck on a small basic problem ..
need to write to a file but using values from subsequent observations ..
the attached image explains the issue .. please help with code to replace "????????" part ..
thanks
Something like this?
data test;
input ID Name$ Month$ Amount;
infile datalines dlm=',' dsd;
cards;
1001,Jenny,JAN,300
1001,,JUL,550
1001,,DEC,275
1002,George,AUG,100
1003,Frank,FEB,375
1003,,NOV,460
;
data _null_;
set test;
by ID;
file 'Yourpath\Donations.txt';
if first.ID then put "Hi " Name
/ "Your donation(s) are as follows"
/ Month Amount dollar10.2;
if not first.ID then put Month Amount dollar10.2;
run;
So the window is what you want the txt file to look like, correct?
Can you post the code here so we can provide a code answer?
sure ...
data _null_;
infile datalines;
input ID Name$ 6-13 Month$ Amount;
file '/folders/myfolders/Donations.txt' print;
PUT
'Hi' name
//'Your donation(s) are as follows:'
// ???????;
put _page_;
cards;
1001 Jenny JAN 300
1001 JUL 550
1001 DEC 275
1002 George AUG 100
1003 Frank FEB 375
1003 NOV 460
;
Is this what your actual data looks like? This is probably not the data you want to work with?
data test;
input ID Name$ Month$ Amount;
cards;
1001 Jenny JAN 300
1001 JUL 550
1001 DEC 275
1002 George AUG 100
1003 Frank FEB 375
1003 NOV 460
;
I'm guessing your data looks more like this?
data test;
input ID Name$ Month$ Amount;
infile datalines dlm=',' dsd;
cards;
1001,Jenny,JAN,300
1001,,JUL,550
1001,,DEC,275
1002,George,AUG,100
1003,Frank,FEB,375
1003,,NOV,460
;
looks more like this ... copy/paste is screwing up the spacing
i wouldn't mind making a dataset with this data and then using the dataset to generate the txt files either ... so we can use the BY statement (in case first. and last. needs to be used)
----x----1----x----2----x----3
1001 Jenny JAN 300
1001 JUL 550
1001 DEC 275
1002 George AUG 100
1003 Frank FEB 375
1003 NOV 460
;
Something like this?
data test;
input ID Name$ Month$ Amount;
infile datalines dlm=',' dsd;
cards;
1001,Jenny,JAN,300
1001,,JUL,550
1001,,DEC,275
1002,George,AUG,100
1003,Frank,FEB,375
1003,,NOV,460
;
data _null_;
set test;
by ID;
file 'Yourpath\Donations.txt';
if first.ID then put "Hi " Name
/ "Your donation(s) are as follows"
/ Month Amount dollar10.2;
if not first.ID then put Month Amount dollar10.2;
run;
Next time post your code within the man-icon window.
Replace the '????...?' with:
month $3. amount 7.2 /
but you still need to recognize a start of a new name, so your code need be -
Suppose you read your input into sas dataset named 'have':
data _null_;
set have;
file .... /* your code */
if not missing(name) then
put 'Hi ' name // 'Your do.....: ' /* your text */
/ month $3. amount dollar7.2 ;
else put / mont $3. amount dollar7.2;
run;
thanks all !!!
I love this site and these boards !!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.