So, you don't care about the "Xyz", "gef" and so on?
Like this?
data HAVE;
input A B :$20.;
COL=scan(B,1,'":');
VAL=scan(B,2,'":');
if COL='Xyz' then ROW+1;
cards;
1 "Xyz":"123"
2 "gef":"abc23"
3 "rod":"124899"
4. "Xyz":"567"
5. "gef":"ijk67"
6. "rod":"800775"
;
proc transpose data=HAVE out=WANT;
var VAL;
id COL;
by ROW;
run;
ROW | _NAME_ | Xyz | gef | rod |
---|---|---|---|---|
1 | VAL | 123 | abc23 | 124899 |
2 | VAL | 567 | ijk67 | 800775 |
Suggestion: Copy a few lines, if the example you show is good, 12 or 15 should do as text from your and on the forum open a text box using the </> icon above the message window and paste the example text.
The message windows on this forum will reformat pasted text and may acquire non-printable characters making the example that you posted very likely not exactly as the source file actually is.
Any description you may have, such as the types of values, numeric or character, and the maximum lengths would be a good idea if available. Note: "123" might need to be numeric for you or character, we can't tell.
Also, were the 1 through 6 your example line numbers or do they appear in the data file, same with your "want" example.
@Pandu2 wrote:
Those values must be character like 123,abc23 etc. And also 1through 6 are serial numbers
So, if the 1 through 6 are in your data where to did the 3, 4, 5 and 6 go?
Character variables have length. If you don't tell what the longest expected length is for any value then you may not have the entire value represented.
Variables you don't want can always be DROPped from the data set.
The example solution posted by @ChrisNZ uses inline data because we do not have a file. Use an INFILE statement to point to your data file instead of using the datalines. Basic SAS programming.
@Pandu2 wrote:
I tried using infile statement but in the end the dataset seemed blank nd also the length of the character supposed to 50
Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: 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 "</>" icon or attached as text to show exactly what you have and that we can test code against.
Include all the code to read the file submitted along with all messages
Basics first.
Is this a SAS dataset you get from somewhere without having control over it, or do you get an external (to SAS) file that you import into SAS yourself?
If the first, are the quotes actually part of the data, and not caused by some kind of format?
If the latter, we need to see an example of the source; if it is some kind of text, open the file with a text editor and copy/paste it into a code box opened with this button:
So it is an external file. Please post your code that reads it.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.