The attached NCDebt.csv file is the input file for the code in the attached .txt file labelled "Code." The code runs the way that I want it to, but I have the following item that I need to address.
The "Desired Output.txt" file is not generated by the code, however, it holds the structure that I want my Code-generated output to follow; you will notice similarities in the structure of the output generated once you run the code and the structure of the contents in the "Desired Output.txt file." My problem is that I cannot think of a way to write SAS code such that I can add the 'end' line found at the bottom of the Desired Output.txt file. I have commented out the "End='end'" line in the second datastep of my Code (this was my last ditch effort); when I transpose in the proc step, however, I am still stuck with the variable name End, which I don't want. Ideally, I would have a blank in the variable name and retain the value 'end.'
Any takers?
Sorry about the put _all_ error. This may come closer, change the name of the file to what you want for your text file.
data _null_;
file 'd:\data\output.txt';
set work.Ncdebt3 end= last;
put _NAME_ col1-col9;
if last then put 'End';
run;
I suspect the unwanted END variable is occurring because of the RETAIN statement when creating NCDebt2. I removed that from the data step then ran the transpose code and the above.
Maybe something like;
data _null_;
file 'Your desired output file name goes here';
set Ncdebt3 (end= last);
put _all_;
if last then put 'End';
run;
I tried the following; still no go.
data test;
set Ncdebt3 end= last;
put _all_;
if last then put 'end';
run;
"Still no go" is not a very good description of what you got!
PGStats,
My apologies; by "still no go" I meant that I did not achieve my desired result; the Ncdebt3 dataset in my code above remains unchanged. I attach my log if it helps.
Why is obs #3 skipped (with firstobs=4)? Why would there be only 6 values present in the multi-valued rows of Desired Output.txt? What would make some rows multi-values and others not, in Desired Output.txt?
PGStats,
The end-goal of my code is to prepare a .txt file to be fed into a model. The multi- vs single- value rows issue is somewhat arbitrary and is model-dependent, so I don't have a clear-cut rule to give you. Starting at observation 4 is also model-driven. Mind you, however, that none of the two issues that you raise are related to my original question.
I hope this helps.
The code I posted is NOT intended to create a dataset but an output TEXT file which was sort of implied by the use of "desired output text" as the zip file demonstrated. If you want a data set then some more specific description of the output is needed.
Sorry about the put _all_ error. This may come closer, change the name of the file to what you want for your text file.
data _null_;
file 'd:\data\output.txt';
set work.Ncdebt3 end= last;
put _NAME_ col1-col9;
if last then put 'End';
run;
I suspect the unwanted END variable is occurring because of the RETAIN statement when creating NCDebt2. I removed that from the data step then ran the transpose code and the above.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.